Skip to content

feat(compose): expose structured field mapping errors - #1160

Open
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-1027-field-mapping-error
Open

feat(compose): expose structured field mapping errors#1160
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-1027-field-mapping-error

Conversation

@March-77

Copy link
Copy Markdown

What type of PR is this?

feat

Check the PR title.

  • This PR title matches the format: <type>(optional scope): <description>.
  • The description is user-oriented and clear enough for others to understand.
  • A separate user-documentation PR is not required; the additive Go API is documented inline.

(Optional) Translate the PR title into Chinese.

feat(compose): 暴露结构化 FieldMapping 错误

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

Field mapping failures were exposed as unrelated formatted strings. Callers and tracing handlers could not reliably classify a failure or identify the graph edge and field paths involved.

This PR adds an exported FieldMappingError and stable FieldMappingErrorReason values. Compile-time and deferred runtime mapping failures now carry source/target node keys, human-readable source/target field paths, expected/actual types where applicable, and the original cause. Error() and Unwrap() preserve existing error text and internal errors.As behavior.

Regression coverage verifies structured context for missing and unexported fields at compile time, plus missing nested fields and type mismatches through both Invoke and Stream paths.

User impact: applications can classify field mapping failures with errors.As and attach precise graph context to logs or traces without parsing error strings.

Compatibility/risk: additive public API only. Mapping behavior and existing error messages are unchanged. The main risk is incomplete classification of an uncommon mapping failure; unknown causes still retain their original error through Cause.

Validation:

  • go test ./compose -count=1 (pass)
  • go test ./... -count=1 (pass)
  • go test -race ./compose -count=1 (pass)
  • go vet ./... (pass)
  • gofmt -s -d compose/field_mapping.go compose/graph.go compose/field_mapping_error_test.go (no diff)
  • git diff --check (pass)
  • golangci-lint run ./compose --timeout 5m could not start because the first-time v2.12.2 tool download stalled on a transitive dependency; the process was stopped after the install retry made no progress.

zh(optional):

新增可通过 errors.As 获取的结构化 FieldMapping 错误,包含图边两端节点、字段路径、原因及类型信息,同时保留原有错误文案和错误链。

(Optional) Which issue(s) this PR fixes:

Fixes #1027

(optional) The PR that updates user documentation:

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] 将 FieldMapping 错误统一为结构化 FieldMappingError,携带源/目标节点、字段路径与类型信息

1 participant