ALPHA: wire is a tool to deploy nixos systems wire.althaea.zone/
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

drop error code links (#394)

authored by

marshmallow and committed by
GitHub
9c6218d0 41d0f2fa

+41 -359
+4
CHANGELOG.md
··· 12 12 - Fix a bug where key permissions where being printed in decimal format instead 13 13 of octal. 14 14 15 + ### Removed 16 + 17 + - Remove "Error Codes" documentation page & links. 18 + 15 19 ## [v1.1.1] - 2025-01-05 16 20 17 21 ### Fixed
-7
crates/cli/default.nix
··· 86 86 wire-small-perf = self'.packages.wire-small.overrideAttrs { 87 87 paths = [ self'.packages.wire-unwrapped-perf ]; 88 88 }; 89 - 90 - wire-diagnostics-md = self'.packages.wire-unwrapped.overrideAttrs { 91 - DIAGNOSTICS_MD_OUTPUT = "/build/source"; 92 - installPhase = '' 93 - mv /build/source/DIAGNOSTICS.md $out 94 - ''; 95 - }; 96 89 }; 97 90 }; 98 91 }
-206
crates/core/build.rs
··· 1 - // SPDX-License-Identifier: AGPL-3.0-or-later 2 - // Copyright 2024-2025 wire Contributors 3 - 4 - use miette::{Context, IntoDiagnostic as _, Result, miette}; 5 - use std::fmt::Write; 6 - use std::{ 7 - env, 8 - fmt::{self, Display, Formatter}, 9 - fs::{self}, 10 - path::Path, 11 - }; 12 - 13 - use itertools::Itertools; 14 - use proc_macro2::TokenTree; 15 - use syn::{Expr, Item, ItemEnum, Lit, Meta, MetaList, MetaNameValue, parse_file}; 16 - 17 - macro_rules! p { 18 - ($($tokens: tt)*) => { 19 - println!("cargo::warning={}", format!($($tokens)*)) 20 - } 21 - } 22 - 23 - #[derive(Debug)] 24 - struct DerivedError { 25 - code: Option<String>, 26 - help: Option<String>, 27 - message: Option<String>, 28 - doc_string: String, 29 - } 30 - 31 - impl Display for DerivedError { 32 - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 33 - write!( 34 - f, 35 - "## `{code}` {{#{code}}} 36 - 37 - {doc} 38 - {message} 39 - {help}", 40 - doc = self.doc_string, 41 - code = self.code.as_ref().unwrap(), 42 - help = match &self.help { 43 - Some(help) => format!( 44 - " 45 - ::: tip HELP 46 - {help} 47 - :::" 48 - ), 49 - None => String::new(), 50 - }, 51 - message = match &self.message { 52 - Some(message) => format!( 53 - " 54 - ```txt [message] 55 - {message} 56 - ```" 57 - ), 58 - None => String::new(), 59 - } 60 - ) 61 - } 62 - } 63 - 64 - impl DerivedError { 65 - fn get_error(&mut self, list: &MetaList) -> Result<(), miette::Error> { 66 - if list.path.segments.last().unwrap().ident != "error" { 67 - return Err(miette!("Not an error")); 68 - } 69 - 70 - self.message = Some( 71 - list.tokens 72 - .clone() 73 - .into_iter() 74 - .filter(|tok| matches!(tok, TokenTree::Literal(tok) if tok.to_string().starts_with('"'))) 75 - .map(|tok| tok.to_string()) 76 - .join(""), 77 - ); 78 - 79 - Err(miette!("No error msg found")) 80 - } 81 - 82 - fn update_diagnostic(&mut self, list: &MetaList) -> Result<(), miette::Error> { 83 - if list.path.segments.last().unwrap().ident != "diagnostic" { 84 - return Err(miette!("Not a diagnostic")); 85 - } 86 - 87 - let vec: Vec<_> = list.tokens.clone().into_iter().collect(); 88 - 89 - // Find `diagnostic(code(x::y::z))` 90 - let code: Option<String> = if let Some((_, TokenTree::Group(group))) = 91 - vec.iter().tuple_windows().find(|(ident, group)| { 92 - matches!(ident, TokenTree::Ident(ident) if ident == "code") 93 - && matches!(group, TokenTree::Group(..)) 94 - }) { 95 - Some(group.stream().to_string().replace(' ', "")) 96 - } else { 97 - None 98 - }; 99 - 100 - // Find `diagnostic(help("hi"))` 101 - let help: Option<String> = if let Some((_, TokenTree::Group(group))) = 102 - vec.iter().tuple_windows().find(|(ident, group)| { 103 - matches!(ident, TokenTree::Ident(ident) if ident == "help") 104 - && matches!(group, TokenTree::Group(..)) 105 - }) { 106 - Some(group.stream().to_string()) 107 - } else { 108 - None 109 - }; 110 - 111 - if let Some(code) = code { 112 - self.code = Some(code); 113 - self.help = help; 114 - return Ok(()); 115 - } 116 - 117 - Err(miette!("Had no code.")) 118 - } 119 - 120 - fn update_from_list(&mut self, list: &MetaList) { 121 - let _ = self.get_error(list); 122 - let _ = self.update_diagnostic(list); 123 - } 124 - 125 - fn update_from_namevalue(&mut self, list: MetaNameValue) -> Result<(), miette::Error> { 126 - if list.path.segments.last().unwrap().ident != "doc" { 127 - return Err(miette!("Not a doc string")); 128 - } 129 - 130 - if let Expr::Lit(lit) = list.value 131 - && let Lit::Str(str) = lit.lit 132 - { 133 - let _ = write!(self.doc_string, "{}\n\n", &str.value()[1..]); 134 - } 135 - 136 - Ok(()) 137 - } 138 - } 139 - 140 - fn main() -> Result<()> { 141 - println!("cargo:rerun-if-changed=src/errors.rs"); 142 - 143 - let manifest_dir = env::var("CARGO_MANIFEST_DIR").into_diagnostic()?; 144 - let Ok(md_out_dir) = env::var("DIAGNOSTICS_MD_OUTPUT") else { 145 - return Ok(()); 146 - }; 147 - 148 - let src_path = Path::new(&manifest_dir).join("src/errors.rs"); 149 - let src = fs::read_to_string(&src_path) 150 - .into_diagnostic() 151 - .wrap_err("reading errors.rs")?; 152 - 153 - let syntax_tree = parse_file(&src) 154 - .into_diagnostic() 155 - .wrap_err("parsing errors.rs")?; 156 - let mut entries: Vec<DerivedError> = Vec::new(); 157 - 158 - for item in &syntax_tree.items { 159 - if let Item::Enum(ItemEnum { variants, .. }) = item { 160 - for variant in variants { 161 - let mut entry = DerivedError { 162 - code: None, 163 - help: None, 164 - message: None, 165 - doc_string: String::new(), 166 - }; 167 - 168 - for attribute in variant.attrs.clone() { 169 - match attribute.meta { 170 - Meta::List(list) => { 171 - entry.update_from_list(&list); 172 - } 173 - Meta::NameValue(nv) => { 174 - let _ = entry.update_from_namevalue(nv); 175 - } 176 - Meta::Path(_) => {} 177 - } 178 - } 179 - 180 - if entry.code.is_some() { 181 - entries.push(entry); 182 - } 183 - } 184 - } 185 - } 186 - 187 - fs::create_dir_all(Path::new(&md_out_dir)) 188 - .into_diagnostic() 189 - .wrap_err("creating target directory")?; 190 - fs::write( 191 - Path::new(&md_out_dir).join("DIAGNOSTICS.md"), 192 - entries 193 - .iter() 194 - .map(std::string::ToString::to_string) 195 - .join("\n\n"), 196 - ) 197 - .into_diagnostic() 198 - .wrap_err("writing DIAGNOSTICS.md")?; 199 - 200 - p!( 201 - "wrote to {:?}", 202 - Path::new(&md_out_dir).join("DIAGNOSTICS.md") 203 - ); 204 - 205 - Ok(()) 206 - }
+35 -132
crates/core/src/errors.rs
··· 12 12 13 13 use crate::hive::node::{Name, SwitchToConfigurationGoal}; 14 14 15 - #[cfg(debug_assertions)] 16 - const DOCS_URL: &str = "http://localhost:5173/reference/errors.html"; 17 - #[cfg(not(debug_assertions))] 18 - const DOCS_URL: &str = "https://wire.althaea.zone/reference/errors.html"; 19 - 20 15 #[derive(Debug, Diagnostic, Error)] 21 16 pub enum KeyError { 22 - #[diagnostic( 23 - code(wire::key::File), 24 - url("{DOCS_URL}#{}", self.code().unwrap()) 25 - )] 17 + #[diagnostic(code(wire::key::File))] 26 18 #[error("error reading file")] 27 19 File(#[source] std::io::Error), 28 20 29 21 #[diagnostic( 30 22 code(wire::key::SpawningCommand), 31 - help("Ensure wire has the correct $PATH for this command"), 32 - url("{DOCS_URL}#{}", self.code().unwrap()) 23 + help("Ensure wire has the correct $PATH for this command") 33 24 )] 34 25 #[error("error spawning key command")] 35 26 CommandSpawnError { ··· 43 34 command_span: Option<SourceSpan>, 44 35 }, 45 36 46 - #[diagnostic( 47 - code(wire::key::Resolving), 48 - url("{DOCS_URL}#{}", self.code().unwrap()) 49 - )] 37 + #[diagnostic(code(wire::key::Resolving))] 50 38 #[error("Error resolving key command child process")] 51 39 CommandResolveError { 52 40 #[source] ··· 56 44 command: String, 57 45 }, 58 46 59 - #[diagnostic( 60 - code(wire::key::CommandExit), 61 - url("{DOCS_URL}#{}", self.code().unwrap()) 62 - )] 47 + #[diagnostic(code(wire::key::CommandExit))] 63 48 #[error("key command failed with status {}: {}", .0,.1)] 64 49 CommandError(ExitStatus, String), 65 50 66 - #[diagnostic( 67 - code(wire::key::Empty), 68 - url("{DOCS_URL}#{}", self.code().unwrap()) 69 - )] 51 + #[diagnostic(code(wire::key::Empty))] 70 52 #[error("Command list empty")] 71 53 Empty, 72 54 73 55 #[diagnostic( 74 56 code(wire::key::ParseKeyPermissions), 75 - help("Refer to the documentation for the format of key file permissions."), 76 - url("{DOCS_URL}#{}", self.code().unwrap()) 57 + help("Refer to the documentation for the format of key file permissions.") 77 58 )] 78 59 #[error("Failed to parse key permissions")] 79 60 ParseKeyPermissions(#[source] ParseIntError), ··· 81 62 82 63 #[derive(Debug, Diagnostic, Error)] 83 64 pub enum ActivationError { 84 - #[diagnostic( 85 - code(wire::activation::SwitchToConfiguration), 86 - url("{DOCS_URL}#{}", self.code().unwrap()) 87 - )] 65 + #[diagnostic(code(wire::activation::SwitchToConfiguration))] 88 66 #[error("failed to run switch-to-configuration {0} on node {1}")] 89 67 SwitchToConfigurationError(SwitchToConfigurationGoal, Name, #[source] CommandError), 90 68 } ··· 95 73 code(wire::network::HostUnreachable), 96 74 help( 97 75 "If you failed due to a fault in DNS, note that a node can have multiple targets defined." 98 - ), 99 - url("{DOCS_URL}#{}", self.code().unwrap()) 76 + ) 100 77 )] 101 78 #[error("Cannot reach host {host}")] 102 79 HostUnreachable { ··· 105 82 source: CommandError, 106 83 }, 107 84 108 - #[diagnostic( 109 - code(wire::network::HostUnreachableAfterReboot), 110 - url("{DOCS_URL}#{}", self.code().unwrap()) 111 - )] 85 + #[diagnostic(code(wire::network::HostUnreachableAfterReboot))] 112 86 #[error("Failed to get regain connection to {0} after activation.")] 113 87 HostUnreachableAfterReboot(String), 114 88 115 - #[diagnostic( 116 - code(wire::network::HostsExhausted), 117 - url("{DOCS_URL}#{}", self.code().unwrap()) 118 - )] 89 + #[diagnostic(code(wire::network::HostsExhausted))] 119 90 #[error("Ran out of contactable hosts")] 120 91 HostsExhausted, 121 92 } ··· 126 97 code(wire::hive_init::NoHiveFound), 127 98 help( 128 99 "Double check the path is correct. You can adjust the hive path with `--path` when the hive lies outside of the CWD." 129 - ), 130 - url("{DOCS_URL}#{}", self.code().unwrap()) 100 + ) 131 101 )] 132 102 #[error("No hive could be found in {}", .0.display())] 133 103 NoHiveFound(PathBuf), 134 104 135 105 #[diagnostic( 136 106 code(wire::hive_init::Parse), 137 - help("If you cannot resolve this problem, please create an issue."), 138 - url("{DOCS_URL}#{}", self.code().unwrap()) 107 + help("If you cannot resolve this problem, please create an issue.") 139 108 )] 140 109 #[error("Failed to parse internal wire json.")] 141 110 ParseEvaluateError(#[source] serde_json::Error), 142 111 143 - #[diagnostic( 144 - code(wire::hive_init::ParsePrefetch), 145 - help("please create an issue."), 146 - url("{DOCS_URL}#{}", self.code().unwrap()) 147 - )] 112 + #[diagnostic(code(wire::hive_init::ParsePrefetch), help("please create an issue."))] 148 113 #[error("Failed to parse `nix flake prefetch --json`.")] 149 114 ParsePrefetchError(#[source] serde_json::Error), 150 115 151 116 #[diagnostic( 152 117 code(wire::hive_init::NodeDoesNotExist), 153 - help("Please create an issue!"), 154 - url("{DOCS_URL}#{}", self.code().unwrap()) 118 + help("Please create an issue!") 155 119 )] 156 120 #[error("node {0} not exist in hive")] 157 121 NodeDoesNotExist(String), ··· 159 123 160 124 #[derive(Debug, Diagnostic, Error)] 161 125 pub enum HiveLocationError { 162 - #[diagnostic( 163 - code(wire::hive_location::MalformedPath), 164 - url("{DOCS_URL}#{}", self.code().unwrap()) 165 - )] 126 + #[diagnostic(code(wire::hive_location::MalformedPath))] 166 127 #[error("Path was malformed: {}", .0.display())] 167 128 MalformedPath(PathBuf), 168 129 169 - #[diagnostic( 170 - code(wire::hive_location::Malformed), 171 - url("{DOCS_URL}#{}", self.code().unwrap()) 172 - )] 130 + #[diagnostic(code(wire::hive_location::Malformed))] 173 131 #[error("--path was malformed")] 174 132 Malformed(#[source] FlakeRefError), 175 133 176 - #[diagnostic( 177 - code(wire::hive_location::TypeUnsupported), 178 - url("{DOCS_URL}#{}", self.code().unwrap()) 179 - )] 134 + #[diagnostic(code(wire::hive_location::TypeUnsupported))] 180 135 #[error("The flakref had an unsupported type: {:#?}", .0)] 181 136 TypeUnsupported(Box<FlakeRef>), 182 137 } 183 138 184 139 #[derive(Debug, Diagnostic, Error)] 185 140 pub enum CommandError { 186 - #[diagnostic( 187 - code(wire::command::TermAttrs), 188 - url("{DOCS_URL}#{}", self.code().unwrap()) 189 - )] 141 + #[diagnostic(code(wire::command::TermAttrs))] 190 142 #[error("Failed to set PTY attrs")] 191 143 TermAttrs(#[source] nix::errno::Errno), 192 144 193 - #[diagnostic( 194 - code(wire::command::PosixPipe), 195 - url("{DOCS_URL}#{}", self.code().unwrap()) 196 - )] 145 + #[diagnostic(code(wire::command::PosixPipe))] 197 146 #[error("There was an error in regards to a pipe")] 198 147 PosixPipe(#[source] nix::errno::Errno), 199 148 200 149 /// Error wrapped around `portable_pty`'s anyhow 201 150 /// errors 202 - #[diagnostic( 203 - code(wire::command::PortablePty), 204 - url("{DOCS_URL}#{}", self.code().unwrap()) 205 - )] 151 + #[diagnostic(code(wire::command::PortablePty))] 206 152 #[error("There was an error from the portable_pty crate")] 207 153 PortablePty(#[source] anyhow::Error), 208 154 209 - #[diagnostic( 210 - code(wire::command::Joining), 211 - url("{DOCS_URL}#{}", self.code().unwrap()) 212 - )] 155 + #[diagnostic(code(wire::command::Joining))] 213 156 #[error("Failed to join on some tokio task")] 214 157 JoinError(#[source] JoinError), 215 158 216 - #[diagnostic( 217 - code(wire::command::WaitForStatus), 218 - url("{DOCS_URL}#{}", self.code().unwrap()) 219 - )] 159 + #[diagnostic(code(wire::command::WaitForStatus))] 220 160 #[error("Failed to wait for the child's status")] 221 161 WaitForStatus(#[source] std::io::Error), 222 162 223 163 #[diagnostic( 224 164 code(wire::detached::NoHandle), 225 - help("This should never happen, please create an issue!"), 226 - url("{DOCS_URL}#{}", self.code().unwrap()) 165 + help("This should never happen, please create an issue!") 227 166 )] 228 167 #[error("There was no handle to child io")] 229 168 NoHandle, 230 169 231 - #[diagnostic( 232 - code(wire::command::WritingClientStdout), 233 - url("{DOCS_URL}#{}", self.code().unwrap()) 234 - )] 170 + #[diagnostic(code(wire::command::WritingClientStdout))] 235 171 #[error("Failed to write to client stderr.")] 236 172 WritingClientStderr(#[source] std::io::Error), 237 173 238 - #[diagnostic( 239 - code(wire::command::WritingMasterStdin), 240 - url("{DOCS_URL}#{}", self.code().unwrap()) 241 - )] 174 + #[diagnostic(code(wire::command::WritingMasterStdin))] 242 175 #[error("Failed to write to PTY master stdout.")] 243 176 WritingMasterStdout(#[source] std::io::Error), 244 177 245 - #[diagnostic( 246 - code(wire::command::Recv), 247 - url("{DOCS_URL}#{}", self.code().unwrap()), 248 - help("please create an issue!"), 249 - )] 178 + #[diagnostic(code(wire::command::Recv), help("please create an issue!"))] 250 179 #[error("Failed to receive a message from the begin channel")] 251 180 RecvError(#[source] RecvError), 252 181 253 - #[diagnostic( 254 - code(wire::command::ThreadPanic), 255 - url("{DOCS_URL}#{}", self.code().unwrap()), 256 - help("please create an issue!"), 257 - )] 182 + #[diagnostic(code(wire::command::ThreadPanic), help("please create an issue!"))] 258 183 #[error("Thread panicked")] 259 184 ThreadPanic, 260 185 261 186 #[diagnostic( 262 187 code(wire::command::CommandFailed), 263 - url("{DOCS_URL}#{}", self.code().unwrap()), 264 - help("`nix` commands are filtered, run with -vvv to view all"), 188 + help("`nix` commands are filtered, run with -vvv to view all") 265 189 )] 266 190 #[error("{command_ran} failed ({reason}) with {code} (last 20 lines):\n{logs}")] 267 191 CommandFailed { ··· 271 195 reason: &'static str, 272 196 }, 273 197 274 - #[diagnostic( 275 - code(wire::command::RuntimeDirectory), 276 - url("{DOCS_URL}#{}", self.code().unwrap()) 277 - )] 198 + #[diagnostic(code(wire::command::RuntimeDirectory))] 278 199 #[error("error creating $XDG_RUNTIME_DIR/wire")] 279 200 RuntimeDirectory(#[source] std::io::Error), 280 201 281 - #[diagnostic( 282 - code(wire::command::RuntimeDirectoryMissing), 283 - url("{DOCS_URL}#{}", self.code().unwrap()) 284 - )] 202 + #[diagnostic(code(wire::command::RuntimeDirectoryMissing))] 285 203 #[error("$XDG_RUNTIME_DIR could not be used.")] 286 204 RuntimeDirectoryMissing(#[source] std::env::VarError), 287 205 288 - #[diagnostic( 289 - code(wire::command::OneshotRecvError), 290 - url("{DOCS_URL}#{}", self.code().unwrap()) 291 - )] 206 + #[diagnostic(code(wire::command::OneshotRecvError))] 292 207 #[error("Error waiting for begin message")] 293 208 OneshotRecvError(#[source] tokio::sync::oneshot::error::RecvError), 294 209 } ··· 323 238 KeyError, 324 239 ), 325 240 326 - #[diagnostic( 327 - code(wire::BuildNode), 328 - url("{DOCS_URL}#{}", self.code().unwrap()) 329 - )] 241 + #[diagnostic(code(wire::BuildNode))] 330 242 #[error("failed to build node {name}")] 331 243 NixBuildError { 332 244 name: Name, ··· 334 246 source: CommandError, 335 247 }, 336 248 337 - #[diagnostic( 338 - code(wire::CopyPath), 339 - url("{DOCS_URL}#{}", self.code().unwrap()) 340 - )] 249 + #[diagnostic(code(wire::CopyPath))] 341 250 #[error("failed to copy path {path} to node {name}")] 342 251 NixCopyError { 343 252 name: Name, ··· 360 269 help: Option<Box<String>>, 361 270 }, 362 271 363 - #[diagnostic( 364 - code(wire::Encoding), 365 - url("{DOCS_URL}#{}", self.code().unwrap()) 366 - )] 272 + #[diagnostic(code(wire::Encoding))] 367 273 #[error("error encoding length delimited data")] 368 274 Encoding(#[source] std::io::Error), 369 275 370 - #[diagnostic( 371 - code(wire::SIGINT), 372 - url("{DOCS_URL}#{}", self.code().unwrap()) 373 - )] 276 + #[diagnostic(code(wire::SIGINT))] 374 277 #[error("SIGINT received, shut down")] 375 278 Sigint, 376 279 }
-1
doc/.vitepress/config.ts
··· 143 143 { text: "CLI", link: "/reference/cli" }, 144 144 { text: "Meta Options", link: "/reference/meta" }, 145 145 { text: "Module Options", link: "/reference/module" }, 146 - { text: "Error Codes", link: "/reference/errors" }, 147 146 ], 148 147 }, 149 148 ],
+2 -2
doc/default.nix
··· 9 9 packages = { 10 10 docs = pkgs.callPackage ./package.nix { 11 11 mode = "stable"; 12 - inherit (self'.packages) wire-small-dev wire-diagnostics-md; 12 + inherit (self'.packages) wire-small-dev; 13 13 }; 14 14 15 15 docs-unstable = pkgs.callPackage ./package.nix { 16 - inherit (self'.packages) wire-small-dev wire-diagnostics-md; 16 + inherit (self'.packages) wire-small-dev; 17 17 }; 18 18 }; 19 19 };
-2
doc/package.nix
··· 3 3 nixosOptionsDoc, 4 4 runCommand, 5 5 wire-small-dev, 6 - wire-diagnostics-md, 7 6 nix, 8 7 nodejs, 9 8 pnpm, ··· 56 55 }; 57 56 patchPhase = '' 58 57 cat ${optionsDoc} >> ./reference/module.md 59 - cat ${wire-diagnostics-md} >> ./reference/errors.md 60 58 wire inspect --markdown-help > ./reference/cli.md 61 59 ''; 62 60 buildPhase = "pnpm run build > build.log 2>&1";
-9
doc/reference/errors.md
··· 1 - --- 2 - comment: true 3 - title: Error Codes 4 - description: Most error codes and their associated documentation. 5 - --- 6 - 7 - # Error Codes 8 - 9 - {{ $frontmatter.description }}