question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It infers the wrong file path from json error msg

See original GitHub issue

When I get an error like:

error: server\src\controllers\driver.rs:241: cannot find struct, variant or union type `Location` in this scope

When I click on it, it opens a non-existing file <project_root>\server\server\src\controllers\driver.rs but it should instead open the right file at <project_root>\server\src\controllers\driver.rs. (Btw, this project is in a workspace, of which server is one crate.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ehusscommented, Jan 15, 2018

what was the actual change to the json msg format

rust-lang/cargo#4788 changed it so that all packages are compiled relative to the workspace root instead of the directory where cargo is run. This means that all paths and symbols are now relative to the workspace root. I have updated cargo metadata (rust-lang/cargo#4938) in order to determine where the workspace root is. I have a PR waiting to merge this into beta which should go through soon. Once that is done, I’ll open a PR for Rust Enhanced to use this.

do you know where the json msg format is documented

AFAIK, it is not explicitly documented. I have just been reading the rust source code to figure things out. My notes on the format are here. The JSON structures are defined in libsyntax/json.rs, and there are some comments in there. The code that formats compiler messages into ASCII art is in librustc_errors/emitter.rs. There is not an exact 1:1 relationship between the internal Rust data structures and the JSON format, but it is usually close enough. Let me know if you have any specific questions, since I’ve had to look at this a lot.

0reactions
Boscopcommented, Jan 15, 2018

I’m curious, what was the actual change to the json msg format? Btw, do you know where the json msg format is documented? The reason I’m asking is because I’m writing a “proxy” for cargo/rustc (compiling another lang to Rust) and the proxy also maps error lines back to lines in the original source using source maps. I got it working but I couldn’t find any doc about the format, and no serde structs. Are there any serde structs somewhere? Btw, I ended up with these (sorry, it’s in my pythonic Rust dialect):

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Level
	error
	warning
	note
	help

#[serde(tag = "reason")]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Msg
	#[serde(rename = "compiler-message")]
	CompilerMessage
		message: Message
		package_id: String
		target: Target
	#[serde(rename = "compiler-artifact")]
	CompilerArtifact
		features: Vec<::serde_json::Value>
		filenames: Vec<String>
		fresh: bool
		package_id: String
		profile: Profile
		target: Target
	#[serde(rename = "build-script-executed")]
	BuildScriptExecuted
		cfgs: Vec<::serde_json::Value>
		env: Vec<::serde_json::Value>
		linked_libs: Vec<String>
		linked_paths: Vec<::serde_json::Value>
		package_id: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Message
	pub children: Vec<Message>
	pub code: Option<Code>
	pub level: Level
	pub message: String
	pub rendered: ::serde_json::Value
	pub spans: Vec<Span>

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Code
	pub code: String
	pub explanation: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Span
	pub byte_end: usize
	pub byte_start: usize
	pub column_end: usize
	pub column_start: usize
	pub expansion: ::serde_json::Value
	pub file_name: String
	pub is_primary: bool
	pub label: ::serde_json::Value
	pub line_end: usize
	pub line_start: usize
	pub suggested_replacement: ::serde_json::Value
	pub text: Vec<Text>

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Text
	pub highlight_end: usize
	pub highlight_start: usize
	pub text: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Target
	pub crate_types: Vec<String>
	pub kind: Vec<String>
	pub name: String
	pub src_path: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Profile
	pub debug_assertions: bool
	pub debuginfo: i64
	pub opt_level: String
	pub overflow_checks: bool
	pub test: bool
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the Invalid JSON Error in WordPress? - Rank Math
In this article, learn how to fix the invalid JSON error - 'Updating failed. The response is not a valid JSON response.' with...
Read more >
How to Fix the Invalid JSON Response Error in WordPress
Learn what's causing the invalid JSON response error on your WordPress site as well as the different ways you can fix it.
Read more >
Cannot fetch local json file, file path error (using a live server ...
I run the index.html with a live server plugin for VSCode. However, no matter what I do, it returns me a 404 Not...
Read more >
JSON error handling
In cases where a JavaScript Object Notation (JSON) transaction fails, the API Gateway can use a JSON error to convey error information to...
Read more >
How to Fix The Invalid JSON Error in WordPress (Beginner's ...
Are you seeing the JSON response is not valid error on your WordPress site? Here's our step by step guide on how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found