Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Unmarshal error with source position #759

Open
rhysd opened this issue Jun 30, 2021 · 0 comments · May be fixed by #901
Open

Feature request: Unmarshal error with source position #759

rhysd opened this issue Jun 30, 2021 · 0 comments · May be fixed by #901

Comments

@rhysd
Copy link

rhysd commented Jun 30, 2021

Hi,

I'm using this library to develop actionlint. Since it is a linter, I want to know the exact source position of unmarshal error so that it can report exact error position with helpful source snippet.

Currently go-yaml/yaml's unmarshal error does not have source position information though line number is embedded in an error message.

Example usage is as follows:

package main

import (
	"fmt"

	"gopkg.in/yaml.v3"
)

func main() {
	in := "#\n - - QI\xd7"

	var n yaml.Node
	if err := yaml.Unmarshal([]byte(in), &n); err != nil {
		err, _ := err.(*yaml.TypeError)
		for _, err := range err.Errors {
			// I want the err.Line and err.Column fields
			fmt.Fprintf("yaml parse failure at line:%d col:%d: %s\n", err.Line, err.Column, err.Message)
		}
		fmt.Fprintf("%d errors found while parsing yaml file\n", len(err.Errors))
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant