Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Allow to get source position of unmarshal error#760

Closed
rhysd wants to merge 2 commits intogo-yaml:v3from
rhysd:error-position
Closed

Allow to get source position of unmarshal error#760
rhysd wants to merge 2 commits intogo-yaml:v3from
rhysd:error-position

Conversation

@rhysd
Copy link

@rhysd rhysd commented Jun 30, 2021

Fixes #759

With this PR, error instances in TypeError.Errors know their source positions. Previously the field was string slice, but now it is slice of struct of message, line and column so that the caller can know where each error occurred exactly.

@andig
Copy link

andig commented Sep 18, 2022

It would be absolutely fantastic to have this capability.

/cc @niemeyer is this blocked in any way? Could a small sponsoring help to move this forward?

@andig
Copy link

andig commented Sep 18, 2022

@rhysd I think there is a second case that's not handled. When decode panics, it moves into handleErr:

func handleErr(err *error) {
	if v := recover(); v != nil {
		if e, ok := v.(yamlError); ok {
			*err = e.err
		} else {
			panic(v)
		}
	}
}

Does yamlError need line information, too?

@rhysd
Copy link
Author

rhysd commented Sep 18, 2022

It would be necessary. But I don't have enough time to update this branch for now.

@andig
Copy link

andig commented Sep 18, 2022

@rhysd Maybe you could take a look- forked your PR and added terminal failures with line numbers.

@rhysd
Copy link
Author

rhysd commented Sep 19, 2022

Looks good to me. Thank you for improving this branch. I'm closing this in favor of #901.

@rhysd rhysd closed this Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Unmarshal error with source position

2 participants