Revamp errors and logging (vercel/turbo#467)
This updates all of our Issues to have a consistent display, and changes the way we display source code and debug-level details. In particular, this makes the following changes: 1. Cleans up the title/description of existing issues - We were filling the `title` field with too much information, because the `desccription` field wasn't always shown. 1. Always displays the `description` - This used to be hidden behind the `--detail` flag 1. Always displays the code frame of the issue, if it exists - This used to be hidden behind the `--detail` flag 1. Fixes the `context` (file path) to display the relative path to the file - It was hardcoded to the FS string used by turbotrace 1. Creates a new `detail` function which can provide debug-level information about the internal Rust state - This is not shown by default, user must pass `--detail` flag The format for a rendered issue roughly matches: ``` ${SEVERITY} [${CATEGORY}] ${CONTEXT} ${TITLE} ${CODE FRAME} ${DESCRIPTION} ${DETAIL} ``` Where - `SEVERITY` is error/warning/etc - `CATEGORY` is a self-defined string for the phase of the compiler (eg, "parsing", "running") - `CONTEXT` is a file path to the offending file - `TITLE` is a short (single-line) title - `CODE_FRAME` is an optional position that generated the issue, which will display a few context lines and highlight the offending span of code - `DESCRIPTION` is a longer (multi-line) message that describes the issue, and what to do about it - `DETAIL` is a (by default not shown) fully detailed, debug-level, message providing insights into the internal state of Rust
This commit is contained in:
parent
9427514d69
commit
4851e09ca8
3 changed files with 26 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use turbo_tasks::{primitives::StringVc, ValueToString};
|
||||
use turbo_tasks::primitives::StringVc;
|
||||
use turbo_tasks_fs::FileSystemPathVc;
|
||||
use turbopack_core::issue::{Issue, IssueVc};
|
||||
|
||||
|
@ -13,11 +13,8 @@ pub struct RenderingIssue {
|
|||
#[turbo_tasks::value_impl]
|
||||
impl Issue for RenderingIssue {
|
||||
#[turbo_tasks::function]
|
||||
async fn title(&self) -> Result<StringVc> {
|
||||
Ok(StringVc::cell(format!(
|
||||
"error during rendering of {}",
|
||||
self.context.to_string().await?,
|
||||
)))
|
||||
fn title(&self) -> StringVc {
|
||||
StringVc::cell("Error during SSR Rendering".to_string())
|
||||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
|
@ -35,6 +32,10 @@ impl Issue for RenderingIssue {
|
|||
self.message
|
||||
}
|
||||
|
||||
// TODO add sub_issue for logging data
|
||||
// TODO parse stack trace
|
||||
#[turbo_tasks::function]
|
||||
fn detail(&self) -> StringVc {
|
||||
self.logging
|
||||
}
|
||||
|
||||
// TODO parse stack trace into source location
|
||||
}
|
||||
|
|
|
@ -40,9 +40,8 @@ pub async fn assert_can_resolve_react_refresh(
|
|||
_ => {
|
||||
ReactRefreshResolvingIssue {
|
||||
path,
|
||||
description: StringVc::cell(format!(
|
||||
"could not resolve the `@next/react-refresh-utils/dist/runtime` \
|
||||
module\nresolve options: {:?}",
|
||||
detail: StringVc::cell(format!(
|
||||
"resolve options: {:?}",
|
||||
resolve_options.dbg().await?
|
||||
)),
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ pub async fn resolve_react_refresh(origin: ResolveOriginVc) -> Result<Ecmascript
|
|||
#[turbo_tasks::value(shared)]
|
||||
pub struct ReactRefreshResolvingIssue {
|
||||
path: FileSystemPathVc,
|
||||
description: StringVc,
|
||||
detail: StringVc,
|
||||
}
|
||||
|
||||
#[turbo_tasks::value_impl]
|
||||
|
@ -97,13 +96,8 @@ impl Issue for ReactRefreshResolvingIssue {
|
|||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
async fn title(&self) -> Result<StringVc> {
|
||||
Ok(StringVc::cell(
|
||||
"An issue occurred while resolving the React Refresh runtime. React Refresh will be \
|
||||
disabled.\nTo enable React Refresh, install the `react-refresh` and \
|
||||
`@next/react-refresh-utils` modules."
|
||||
.to_string(),
|
||||
))
|
||||
fn title(&self) -> StringVc {
|
||||
StringVc::cell("Could not resolve React Refresh runtime".to_string())
|
||||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
|
@ -118,6 +112,15 @@ impl Issue for ReactRefreshResolvingIssue {
|
|||
|
||||
#[turbo_tasks::function]
|
||||
fn description(&self) -> StringVc {
|
||||
self.description
|
||||
StringVc::cell(
|
||||
"React Refresh will be disabled.\nTo enable React Refresh, install the \
|
||||
`react-refresh` and `@next/react-refresh-utils` modules."
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
fn detail(&self) -> StringVc {
|
||||
self.detail
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![feature(future_join)]
|
||||
#![feature(min_specialization)]
|
||||
|
||||
use std::{net::IpAddr, path::MAIN_SEPARATOR, sync::Arc};
|
||||
use std::{env::current_dir, net::IpAddr, path::MAIN_SEPARATOR, sync::Arc};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use next_core::{create_server_rendered_source, create_web_entry_source, env::load_env};
|
||||
|
@ -109,7 +109,7 @@ impl NextDevServerBuilder {
|
|||
let log_detail = self.log_detail;
|
||||
let browserslist_query = self.browserslist_query;
|
||||
let log_options = LogOptions {
|
||||
project_dir: project_dir.clone(),
|
||||
current_dir: current_dir().unwrap(),
|
||||
show_all,
|
||||
log_detail,
|
||||
log_level: self.log_level,
|
||||
|
|
Loading…
Reference in a new issue