feat(tvix/nix-compat): fix and improve error message
Similar to cl/9350. Most of the times, this is still a regular string, so let's print it like that if we can, and resort to base64 encoding if we can't. We were also wrongly always outputting the second character in the string. Change-Id: Id0e2a9d9f1ad3d2d7b554893ecd89a7e6383e9c2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9445 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
		
							parent
							
								
									8de0d6ad48
								
							
						
					
					
						commit
						09a901de5b
					
				
					 1 changed files with 6 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
use crate::nixbase32::{self, Nixbase32DecodeError};
 | 
					use crate::nixbase32::{self, Nixbase32DecodeError};
 | 
				
			||||||
 | 
					use data_encoding::BASE64;
 | 
				
			||||||
use std::{fmt, path::PathBuf, str::FromStr};
 | 
					use std::{fmt, path::PathBuf, str::FromStr};
 | 
				
			||||||
use thiserror;
 | 
					use thiserror;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +29,11 @@ pub enum Error {
 | 
				
			||||||
    InvalidHashEncoding(Nixbase32DecodeError),
 | 
					    InvalidHashEncoding(Nixbase32DecodeError),
 | 
				
			||||||
    #[error("Invalid length")]
 | 
					    #[error("Invalid length")]
 | 
				
			||||||
    InvalidLength(),
 | 
					    InvalidLength(),
 | 
				
			||||||
    #[error("Invalid name: {:?}, character at position {} ('{}') is invalid", .0, .1, .0[1])]
 | 
					    #[error(
 | 
				
			||||||
 | 
					        "Invalid name: \"{}\", character at position {} is invalid",
 | 
				
			||||||
 | 
					        std::str::from_utf8(&.0).unwrap_or(&BASE64.encode(.0)),
 | 
				
			||||||
 | 
					        .1,
 | 
				
			||||||
 | 
					    )]
 | 
				
			||||||
    InvalidName(Vec<u8>, usize),
 | 
					    InvalidName(Vec<u8>, usize),
 | 
				
			||||||
    #[error("Tried to parse an absolute path which was missing the store dir prefix.")]
 | 
					    #[error("Tried to parse an absolute path which was missing the store dir prefix.")]
 | 
				
			||||||
    MissingStoreDir(),
 | 
					    MissingStoreDir(),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue