Skip to content

Expose error and warning locations as data - #22

Merged
marcoroth merged 1 commit into
mainfrom
error-locations
Oct 14, 2026
Merged

marcoroth merged 1 commit into
mainfrom
error-locations

Conversation

@marcoroth

@marcoroth marcoroth commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

This pull request adds the type and location of an error or warning as data, so a tool can point at the source without reading it out of the message with a regular expression.

Errors and warnings used to cross the FFI boundary as a single string, so the location and the kind of error were lost there. The Rust side now sends each one as JSON with a message, a type and a location, and the C extension builds the exception with from_json on the error class before raising it.

The shape follows Prism, Herb and Yerba. A warning is a LightningCSS::Warning with a message, a type and a location, like a diagnostic in Prism or Herb. A LightningCSS::Location is a Data with a filename, a line counted from 1 and a column counted from 0, like a location in all three.

css = ".a { color: red; }\n.b, { color: blue; }\n"

begin
  LightningCSS.transform(css, filename: "main.css")
rescue LightningCSS::ParseError => error
  error.message  #=> "Invalid empty selector at main.css:2:5"
  error.type     #=> "SelectorError"
  error.location #=> #<data LightningCSS::Location filename="main.css", line=2, column=4>
end

warning = LightningCSS.transform(css, filename: "main.css", error_recovery: true).warnings.first

warning.message  #=> "Invalid empty selector"
warning.type     #=> "SelectorError"
warning.location #=> #<data LightningCSS::Location filename="main.css", line=2, column=4>
warning.to_s     #=> "Invalid empty selector at main.css:2:5"

Resolves #18

@marcoroth
marcoroth enabled auto-merge (squash) October 14, 2026 06:45
@marcoroth
marcoroth merged commit 773bd34 into main Oct 14, 2026
11 checks passed
@marcoroth
marcoroth deleted the error-locations branch October 14, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose error and warning locations as data, not only in the message

1 participant