feat(compose): expose structured field mapping errors - #1160
Open
March-77 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
feat
Check the PR title.
<type>(optional scope): <description>.(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
FieldMappingErrorand stableFieldMappingErrorReasonvalues. 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()andUnwrap()preserve existing error text and internalerrors.Asbehavior.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.Asand 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 5mcould 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