From 9c6218d0c2b22c2a725b9fdb506342ecfbf04b71 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Tue, 27 Jan 2026 21:58:15 +0000 Subject: [PATCH] drop error code links (#394) --- CHANGELOG.md | 4 ++++ doc/default.nix | 4 ++-- doc/package.nix | 2 -- crates/cli/default.nix | 7 ------- crates/core/build.rs | 206 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- doc/.vitepress/config.ts | 1 - doc/reference/errors.md | 9 --------- crates/core/src/errors.rs | 167 +++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------ 8 file(s) changed, 41 insertion(s)(+), 359 deletion(s)(-) diff --git a/CHANGELOG.md b/CHANGELOG.md --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ - Fix a bug where key permissions where being printed in decimal format instead of octal. +### Removed + +- Remove "Error Codes" documentation page & links. + ## [v1.1.1] - 2025-01-05 ### Fixed diff --git a/doc/default.nix b/doc/default.nix --- a/doc/default.nix +++ b/doc/default.nix @@ -9,11 +9,11 @@ packages = { docs = pkgs.callPackage ./package.nix { mode = "stable"; - inherit (self'.packages) wire-small-dev wire-diagnostics-md; + inherit (self'.packages) wire-small-dev; }; docs-unstable = pkgs.callPackage ./package.nix { - inherit (self'.packages) wire-small-dev wire-diagnostics-md; + inherit (self'.packages) wire-small-dev; }; }; }; diff --git a/doc/package.nix b/doc/package.nix --- a/doc/package.nix +++ b/doc/package.nix @@ -3,7 +3,6 @@ nixosOptionsDoc, runCommand, wire-small-dev, - wire-diagnostics-md, nix, nodejs, pnpm, @@ -56,7 +55,6 @@ }; patchPhase = '' cat ${optionsDoc} >> ./reference/module.md - cat ${wire-diagnostics-md} >> ./reference/errors.md wire inspect --markdown-help > ./reference/cli.md ''; buildPhase = "pnpm run build > build.log 2>&1"; diff --git a/crates/cli/default.nix b/crates/cli/default.nix --- a/crates/cli/default.nix +++ b/crates/cli/default.nix @@ -86,13 +86,6 @@ wire-small-perf = self'.packages.wire-small.overrideAttrs { paths = [ self'.packages.wire-unwrapped-perf ]; }; - - wire-diagnostics-md = self'.packages.wire-unwrapped.overrideAttrs { - DIAGNOSTICS_MD_OUTPUT = "/build/source"; - installPhase = '' - mv /build/source/DIAGNOSTICS.md $out - ''; - }; }; }; } diff --git a/crates/core/build.rs b/crates/core/build.rs deleted file mode 100644 --- a/crates/core/build.rs +++ /dev/null @@ -1,206 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-or-later -// Copyright 2024-2025 wire Contributors - -use miette::{Context, IntoDiagnostic as _, Result, miette}; -use std::fmt::Write; -use std::{ - env, - fmt::{self, Display, Formatter}, - fs::{self}, - path::Path, -}; - -use itertools::Itertools; -use proc_macro2::TokenTree; -use syn::{Expr, Item, ItemEnum, Lit, Meta, MetaList, MetaNameValue, parse_file}; - -macro_rules! p { - ($($tokens: tt)*) => { - println!("cargo::warning={}", format!($($tokens)*)) - } -} - -#[derive(Debug)] -struct DerivedError { - code: Option, - help: Option, - message: Option, - doc_string: String, -} - -impl Display for DerivedError { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!( - f, - "## `{code}` {{#{code}}} - -{doc} -{message} -{help}", - doc = self.doc_string, - code = self.code.as_ref().unwrap(), - help = match &self.help { - Some(help) => format!( - " -::: tip HELP -{help} -:::" - ), - None => String::new(), - }, - message = match &self.message { - Some(message) => format!( - " -```txt [message] -{message} -```" - ), - None => String::new(), - } - ) - } -} - -impl DerivedError { - fn get_error(&mut self, list: &MetaList) -> Result<(), miette::Error> { - if list.path.segments.last().unwrap().ident != "error" { - return Err(miette!("Not an error")); - } - - self.message = Some( - list.tokens - .clone() - .into_iter() - .filter(|tok| matches!(tok, TokenTree::Literal(tok) if tok.to_string().starts_with('"'))) - .map(|tok| tok.to_string()) - .join(""), - ); - - Err(miette!("No error msg found")) - } - - fn update_diagnostic(&mut self, list: &MetaList) -> Result<(), miette::Error> { - if list.path.segments.last().unwrap().ident != "diagnostic" { - return Err(miette!("Not a diagnostic")); - } - - let vec: Vec<_> = list.tokens.clone().into_iter().collect(); - - // Find `diagnostic(code(x::y::z))` - let code: Option = if let Some((_, TokenTree::Group(group))) = - vec.iter().tuple_windows().find(|(ident, group)| { - matches!(ident, TokenTree::Ident(ident) if ident == "code") - && matches!(group, TokenTree::Group(..)) - }) { - Some(group.stream().to_string().replace(' ', "")) - } else { - None - }; - - // Find `diagnostic(help("hi"))` - let help: Option = if let Some((_, TokenTree::Group(group))) = - vec.iter().tuple_windows().find(|(ident, group)| { - matches!(ident, TokenTree::Ident(ident) if ident == "help") - && matches!(group, TokenTree::Group(..)) - }) { - Some(group.stream().to_string()) - } else { - None - }; - - if let Some(code) = code { - self.code = Some(code); - self.help = help; - return Ok(()); - } - - Err(miette!("Had no code.")) - } - - fn update_from_list(&mut self, list: &MetaList) { - let _ = self.get_error(list); - let _ = self.update_diagnostic(list); - } - - fn update_from_namevalue(&mut self, list: MetaNameValue) -> Result<(), miette::Error> { - if list.path.segments.last().unwrap().ident != "doc" { - return Err(miette!("Not a doc string")); - } - - if let Expr::Lit(lit) = list.value - && let Lit::Str(str) = lit.lit - { - let _ = write!(self.doc_string, "{}\n\n", &str.value()[1..]); - } - - Ok(()) - } -} - -fn main() -> Result<()> { - println!("cargo:rerun-if-changed=src/errors.rs"); - - let manifest_dir = env::var("CARGO_MANIFEST_DIR").into_diagnostic()?; - let Ok(md_out_dir) = env::var("DIAGNOSTICS_MD_OUTPUT") else { - return Ok(()); - }; - - let src_path = Path::new(&manifest_dir).join("src/errors.rs"); - let src = fs::read_to_string(&src_path) - .into_diagnostic() - .wrap_err("reading errors.rs")?; - - let syntax_tree = parse_file(&src) - .into_diagnostic() - .wrap_err("parsing errors.rs")?; - let mut entries: Vec = Vec::new(); - - for item in &syntax_tree.items { - if let Item::Enum(ItemEnum { variants, .. }) = item { - for variant in variants { - let mut entry = DerivedError { - code: None, - help: None, - message: None, - doc_string: String::new(), - }; - - for attribute in variant.attrs.clone() { - match attribute.meta { - Meta::List(list) => { - entry.update_from_list(&list); - } - Meta::NameValue(nv) => { - let _ = entry.update_from_namevalue(nv); - } - Meta::Path(_) => {} - } - } - - if entry.code.is_some() { - entries.push(entry); - } - } - } - } - - fs::create_dir_all(Path::new(&md_out_dir)) - .into_diagnostic() - .wrap_err("creating target directory")?; - fs::write( - Path::new(&md_out_dir).join("DIAGNOSTICS.md"), - entries - .iter() - .map(std::string::ToString::to_string) - .join("\n\n"), - ) - .into_diagnostic() - .wrap_err("writing DIAGNOSTICS.md")?; - - p!( - "wrote to {:?}", - Path::new(&md_out_dir).join("DIAGNOSTICS.md") - ); - - Ok(()) -} diff --git a/doc/.vitepress/config.ts b/doc/.vitepress/config.ts --- a/doc/.vitepress/config.ts +++ b/doc/.vitepress/config.ts @@ -143,7 +143,6 @@ { text: "CLI", link: "/reference/cli" }, { text: "Meta Options", link: "/reference/meta" }, { text: "Module Options", link: "/reference/module" }, - { text: "Error Codes", link: "/reference/errors" }, ], }, ], diff --git a/doc/reference/errors.md b/doc/reference/errors.md deleted file mode 100644 --- a/doc/reference/errors.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -comment: true -title: Error Codes -description: Most error codes and their associated documentation. ---- - -# Error Codes - -{{ $frontmatter.description }} diff --git a/crates/core/src/errors.rs b/crates/core/src/errors.rs --- a/crates/core/src/errors.rs +++ b/crates/core/src/errors.rs @@ -12,24 +12,15 @@ use crate::hive::node::{Name, SwitchToConfigurationGoal}; -#[cfg(debug_assertions)] -const DOCS_URL: &str = "http://localhost:5173/reference/errors.html"; -#[cfg(not(debug_assertions))] -const DOCS_URL: &str = "https://wire.althaea.zone/reference/errors.html"; - #[derive(Debug, Diagnostic, Error)] pub enum KeyError { - #[diagnostic( - code(wire::key::File), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::key::File))] #[error("error reading file")] File(#[source] std::io::Error), #[diagnostic( code(wire::key::SpawningCommand), - help("Ensure wire has the correct $PATH for this command"), - url("{DOCS_URL}#{}", self.code().unwrap()) + help("Ensure wire has the correct $PATH for this command") )] #[error("error spawning key command")] CommandSpawnError { @@ -43,10 +34,7 @@ command_span: Option, }, - #[diagnostic( - code(wire::key::Resolving), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::key::Resolving))] #[error("Error resolving key command child process")] CommandResolveError { #[source] @@ -56,24 +44,17 @@ command: String, }, - #[diagnostic( - code(wire::key::CommandExit), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::key::CommandExit))] #[error("key command failed with status {}: {}", .0,.1)] CommandError(ExitStatus, String), - #[diagnostic( - code(wire::key::Empty), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::key::Empty))] #[error("Command list empty")] Empty, #[diagnostic( code(wire::key::ParseKeyPermissions), - help("Refer to the documentation for the format of key file permissions."), - url("{DOCS_URL}#{}", self.code().unwrap()) + help("Refer to the documentation for the format of key file permissions.") )] #[error("Failed to parse key permissions")] ParseKeyPermissions(#[source] ParseIntError), @@ -81,10 +62,7 @@ #[derive(Debug, Diagnostic, Error)] pub enum ActivationError { - #[diagnostic( - code(wire::activation::SwitchToConfiguration), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::activation::SwitchToConfiguration))] #[error("failed to run switch-to-configuration {0} on node {1}")] SwitchToConfigurationError(SwitchToConfigurationGoal, Name, #[source] CommandError), } @@ -95,8 +73,7 @@ code(wire::network::HostUnreachable), help( "If you failed due to a fault in DNS, note that a node can have multiple targets defined." - ), - url("{DOCS_URL}#{}", self.code().unwrap()) + ) )] #[error("Cannot reach host {host}")] HostUnreachable { @@ -105,17 +82,11 @@ source: CommandError, }, - #[diagnostic( - code(wire::network::HostUnreachableAfterReboot), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::network::HostUnreachableAfterReboot))] #[error("Failed to get regain connection to {0} after activation.")] HostUnreachableAfterReboot(String), - #[diagnostic( - code(wire::network::HostsExhausted), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::network::HostsExhausted))] #[error("Ran out of contactable hosts")] HostsExhausted, } @@ -126,32 +97,25 @@ code(wire::hive_init::NoHiveFound), help( "Double check the path is correct. You can adjust the hive path with `--path` when the hive lies outside of the CWD." - ), - url("{DOCS_URL}#{}", self.code().unwrap()) + ) )] #[error("No hive could be found in {}", .0.display())] NoHiveFound(PathBuf), #[diagnostic( code(wire::hive_init::Parse), - help("If you cannot resolve this problem, please create an issue."), - url("{DOCS_URL}#{}", self.code().unwrap()) + help("If you cannot resolve this problem, please create an issue.") )] #[error("Failed to parse internal wire json.")] ParseEvaluateError(#[source] serde_json::Error), - #[diagnostic( - code(wire::hive_init::ParsePrefetch), - help("please create an issue."), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::hive_init::ParsePrefetch), help("please create an issue."))] #[error("Failed to parse `nix flake prefetch --json`.")] ParsePrefetchError(#[source] serde_json::Error), #[diagnostic( code(wire::hive_init::NodeDoesNotExist), - help("Please create an issue!"), - url("{DOCS_URL}#{}", self.code().unwrap()) + help("Please create an issue!") )] #[error("node {0} not exist in hive")] NodeDoesNotExist(String), @@ -159,109 +123,69 @@ #[derive(Debug, Diagnostic, Error)] pub enum HiveLocationError { - #[diagnostic( - code(wire::hive_location::MalformedPath), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::hive_location::MalformedPath))] #[error("Path was malformed: {}", .0.display())] MalformedPath(PathBuf), - #[diagnostic( - code(wire::hive_location::Malformed), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::hive_location::Malformed))] #[error("--path was malformed")] Malformed(#[source] FlakeRefError), - #[diagnostic( - code(wire::hive_location::TypeUnsupported), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::hive_location::TypeUnsupported))] #[error("The flakref had an unsupported type: {:#?}", .0)] TypeUnsupported(Box), } #[derive(Debug, Diagnostic, Error)] pub enum CommandError { - #[diagnostic( - code(wire::command::TermAttrs), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::TermAttrs))] #[error("Failed to set PTY attrs")] TermAttrs(#[source] nix::errno::Errno), - #[diagnostic( - code(wire::command::PosixPipe), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::PosixPipe))] #[error("There was an error in regards to a pipe")] PosixPipe(#[source] nix::errno::Errno), /// Error wrapped around `portable_pty`'s anyhow /// errors - #[diagnostic( - code(wire::command::PortablePty), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::PortablePty))] #[error("There was an error from the portable_pty crate")] PortablePty(#[source] anyhow::Error), - #[diagnostic( - code(wire::command::Joining), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::Joining))] #[error("Failed to join on some tokio task")] JoinError(#[source] JoinError), - #[diagnostic( - code(wire::command::WaitForStatus), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::WaitForStatus))] #[error("Failed to wait for the child's status")] WaitForStatus(#[source] std::io::Error), #[diagnostic( code(wire::detached::NoHandle), - help("This should never happen, please create an issue!"), - url("{DOCS_URL}#{}", self.code().unwrap()) + help("This should never happen, please create an issue!") )] #[error("There was no handle to child io")] NoHandle, - #[diagnostic( - code(wire::command::WritingClientStdout), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::WritingClientStdout))] #[error("Failed to write to client stderr.")] WritingClientStderr(#[source] std::io::Error), - #[diagnostic( - code(wire::command::WritingMasterStdin), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::WritingMasterStdin))] #[error("Failed to write to PTY master stdout.")] WritingMasterStdout(#[source] std::io::Error), - #[diagnostic( - code(wire::command::Recv), - url("{DOCS_URL}#{}", self.code().unwrap()), - help("please create an issue!"), - )] + #[diagnostic(code(wire::command::Recv), help("please create an issue!"))] #[error("Failed to receive a message from the begin channel")] RecvError(#[source] RecvError), - #[diagnostic( - code(wire::command::ThreadPanic), - url("{DOCS_URL}#{}", self.code().unwrap()), - help("please create an issue!"), - )] + #[diagnostic(code(wire::command::ThreadPanic), help("please create an issue!"))] #[error("Thread panicked")] ThreadPanic, #[diagnostic( code(wire::command::CommandFailed), - url("{DOCS_URL}#{}", self.code().unwrap()), - help("`nix` commands are filtered, run with -vvv to view all"), + help("`nix` commands are filtered, run with -vvv to view all") )] #[error("{command_ran} failed ({reason}) with {code} (last 20 lines):\n{logs}")] CommandFailed { @@ -271,24 +195,15 @@ reason: &'static str, }, - #[diagnostic( - code(wire::command::RuntimeDirectory), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::RuntimeDirectory))] #[error("error creating $XDG_RUNTIME_DIR/wire")] RuntimeDirectory(#[source] std::io::Error), - #[diagnostic( - code(wire::command::RuntimeDirectoryMissing), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::RuntimeDirectoryMissing))] #[error("$XDG_RUNTIME_DIR could not be used.")] RuntimeDirectoryMissing(#[source] std::env::VarError), - #[diagnostic( - code(wire::command::OneshotRecvError), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::command::OneshotRecvError))] #[error("Error waiting for begin message")] OneshotRecvError(#[source] tokio::sync::oneshot::error::RecvError), } @@ -323,10 +238,7 @@ KeyError, ), - #[diagnostic( - code(wire::BuildNode), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::BuildNode))] #[error("failed to build node {name}")] NixBuildError { name: Name, @@ -334,10 +246,7 @@ source: CommandError, }, - #[diagnostic( - code(wire::CopyPath), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::CopyPath))] #[error("failed to copy path {path} to node {name}")] NixCopyError { name: Name, @@ -360,17 +269,11 @@ help: Option>, }, - #[diagnostic( - code(wire::Encoding), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::Encoding))] #[error("error encoding length delimited data")] Encoding(#[source] std::io::Error), - #[diagnostic( - code(wire::SIGINT), - url("{DOCS_URL}#{}", self.code().unwrap()) - )] + #[diagnostic(code(wire::SIGINT))] #[error("SIGINT received, shut down")] Sigint, } -- tangled.sh