Skip to content

Commit fd8cf6c

Browse files
committed
translate() and transpose() now return StamError::NoText() if called on annotations that have no text
1 parent cd22109 commit fd8cf6c

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stam"
3-
version = "0.18.0"
3+
version = "0.18.1"
44
edition = "2021"
55
authors = ["Maarten van Gompel <proycon@anaproy.nl>"]
66
description = "STAM is a powerful library for dealing with stand-off annotations on text. This is the Rust library."

src/api/translate.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ impl<'store> Translatable<'store> for ResultItem<'store, Annotation> {
8585
mut config: TranslateConfig,
8686
) -> Result<Vec<AnnotationBuilder<'static>>, StamError> {
8787
if let Some(tset) = self.textselectionset() {
88-
if tset.inner().is_empty() {
89-
return Err(StamError::TranslateError(
90-
"Can not translate an annotation that references no text or text in multiple resources".to_string(),
91-
"(translate annotation)",
92-
));
93-
}
9488
if config.source_side_id.is_none() && self.id().is_some() {
9589
config.source_side_id = Some(
9690
self.id()
@@ -117,9 +111,8 @@ impl<'store> Translatable<'store> for ResultItem<'store, Annotation> {
117111
})
118112
.collect())
119113
} else {
120-
Err(StamError::TranslateError(
121-
"Can not translate an annotation that references no text or text in multiple resources".to_string(),
122-
"(translate annotation)",
114+
Err(StamError::NoText(
115+
"Can not translate an annotation that references no text or text in multiple resources",
123116
))
124117
}
125118
}
@@ -133,9 +126,8 @@ impl<'store> Translatable<'store> for ResultTextSelectionSet<'store> {
133126
) -> Result<Vec<AnnotationBuilder<'static>>, StamError> {
134127
via.valid_translation()?;
135128
if self.inner().is_empty() {
136-
return Err(StamError::TranslateError(
137-
format!("Can not translate empty TextSelectionSet"),
138-
"",
129+
return Err(StamError::NoText(
130+
"Can not translate empty TextSelectionSet",
139131
));
140132
}
141133

src/api/transpose.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ impl<'store> Transposable<'store> for ResultItem<'store, Annotation> {
112112
})
113113
.collect())
114114
} else {
115-
Err(StamError::TransposeError(
116-
"Can not transpose an annotation that references no text or text in multiple resources".to_string(),
117-
"(transpose annotation)",
115+
Err(StamError::NoText(
116+
"Can not transpose an annotation that references no text or text in multiple resources",
118117
))
119118
}
120119
}
@@ -128,9 +127,8 @@ impl<'store> Transposable<'store> for ResultTextSelectionSet<'store> {
128127
) -> Result<Vec<AnnotationBuilder<'static>>, StamError> {
129128
via.valid_transposition()?;
130129
if self.inner().is_empty() {
131-
return Err(StamError::TranslateError(
132-
format!("Can not transpose empty TextSelectionSet"),
133-
"",
130+
return Err(StamError::NoText(
131+
"Can not transpose empty TextSelectionSet",
134132
));
135133
}
136134

0 commit comments

Comments
 (0)