Skip to content

Commit b87cef0

Browse files
committed
feat: add more context to EnvelopeErrors
Some transparent errors did not have any context on inner error either and just forward
1 parent 29a026a commit b87cef0

7 files changed

Lines changed: 16 additions & 6 deletions

File tree

hugr-cli/tests/validate.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn test_mermaid_invalid(bad_hugr_string: String, mut cmd: Command) {
126126
cmd.write_stdin(bad_hugr_string);
127127
cmd.assert()
128128
.failure()
129+
.stderr(contains("unconnected port"))
129130
.stderr(contains("Error validating HUGR"));
130131
}
131132

@@ -137,6 +138,7 @@ fn test_bad_hugr(bad_hugr_string: String, mut val_cmd: Command) {
137138
val_cmd
138139
.assert()
139140
.failure()
141+
.stderr(contains("unconnected port"))
140142
.stderr(contains("Error validating HUGR"));
141143
}
142144

@@ -149,7 +151,8 @@ fn test_bad_json(mut val_cmd: Command) {
149151
val_cmd
150152
.assert()
151153
.failure()
152-
.stderr(contains("Error decoding HUGR envelope"));
154+
.stderr(contains("Error decoding HUGR envelope"))
155+
.stderr(contains("missing field"));
153156
}
154157

155158
#[rstest]
@@ -234,5 +237,6 @@ fn test_validate_known_generator(invalid_hugr_with_generator: Vec<u8>, mut val_c
234237
.assert()
235238
.failure()
236239
.stderr(contains("Error validating HUGR"))
240+
.stderr(contains("unconnected port"))
237241
.stderr(contains("generated by test-generator-v1.0.1"));
238242
}

hugr-core/src/envelope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub enum EnvelopeError {
304304
source: hugr_model::v0::binary::WriteError,
305305
},
306306
/// Error reading a HUGR model payload.
307-
#[error(transparent)]
307+
#[error("Model text parsing error")]
308308
ModelTextRead {
309309
/// The source error.
310310
#[from]

hugr-core/src/envelope/package_json.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ pub(super) fn to_json_writer<'h>(
7777
/// Error raised while loading a package.
7878
#[derive(Debug, Display, Error, From)]
7979
#[non_exhaustive]
80+
#[display("Error reading or writing a package in JSON format.")]
8081
pub enum PackageEncodingError {
8182
/// Error raised while parsing the package json.
82-
JsonEncoding(serde_json::Error),
83+
JsonEncoding(#[from] serde_json::Error),
8384
/// Error raised while reading from a file.
84-
IOError(io::Error),
85+
IOError(#[from] io::Error),
8586
/// Could not resolve the extension needed to encode the hugr.
86-
ExtensionResolution(WithGenerator<ExtensionResolutionError>),
87+
ExtensionResolution(#[from] WithGenerator<ExtensionResolutionError>),
8788
/// Error raised while checking for breaking extension version mismatch.
88-
ExtensionVersion(WithGenerator<ExtensionBreakingError>),
89+
ExtensionVersion(#[from] WithGenerator<ExtensionBreakingError>),
8990
}
9091

9192
/// A private package structure implementing the serde traits.

hugr-core/src/extension.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ pub enum ExtensionRegistryError {
706706
/// An error that can occur while loading an extension registry.
707707
#[derive(Debug, Error)]
708708
#[non_exhaustive]
709+
#[error("Extension registry load error")]
709710
pub enum ExtensionRegistryLoadError {
710711
/// Deserialization error.
711712
#[error(transparent)]

hugr-model/src/v0/ast/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ impl<'a> Context<'a> {
365365
/// Error that may occur in [`Module::resolve`].
366366
#[derive(Debug, Clone, Error)]
367367
#[non_exhaustive]
368+
#[error("Error resolving model module")]
368369
pub enum ResolveError {
369370
/// Unknown variable.
370371
#[error("unknown var: {0}")]

hugr-model/src/v0/binary/read.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::io::BufRead;
88
/// An error encountered while deserialising a model.
99
#[derive(Debug, derive_more::From, derive_more::Display, derive_more::Error)]
1010
#[non_exhaustive]
11+
#[display("Error reading a HUGR model payload.")]
1112
pub enum ReadError {
1213
#[from(forward)]
1314
/// An error encountered while decoding a model from a `capnproto` buffer.

hugr-model/src/v0/binary/write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::v0::table;
77
/// An error encounter while serializing a model.
88
#[derive(Debug, derive_more::From, derive_more::Display, derive_more::Error)]
99
#[non_exhaustive]
10+
#[display("Error encoding a package in HUGR model format.")]
1011
pub enum WriteError {
12+
#[from(forward)]
1113
/// An error encountered while encoding a `capnproto` buffer.
1214
EncodingError(capnp::Error),
1315
}

0 commit comments

Comments
 (0)