mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.98k stars 332 forks source link

Are the errors in the `shell` package any concrete type? #1008

Closed hwittenborn closed 1 year ago

hwittenborn commented 1 year ago

I'm working on using shell.Expand as part of my project, but I was wondering if the return type for errors was anything concrete.

I saw that the error contained some useful line information:

1:5: reached EOF without matching ${ with }

but I wasn't sure how to reliable extract that from the error message. Is there a type I can cast the interface into to pull that information out with?

mvdan commented 1 year ago

Yes, that looks like https://pkg.go.dev/mvdan.cc/sh/v3/syntax#ParseError. You can always look at the type via fmt.Printf("%#v\n", err).

hwittenborn commented 1 year ago

Oh cool, I didn't know you could find out types like that. I'm still learning a bunch about interfaces, so it's definitely a bunch of learning I'm getting done. I'll give that a look in a bit, thanks a ton for the help! :)