Skip to content

Commit 57d2fc2

Browse files
committed
improve a few error messages
1 parent 81a607d commit 57d2fc2

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

cli/Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ anyhow = "1.0.69"
1111
clap = { version = "4.1.6", features = ["derive"] }
1212
dirs = "5.0.1"
1313
postgrest = "1.5.0"
14+
regex = "1.9"
1415
reqwest = { version = "0.11.14", features = ["json", "native-tls-vendored"] }
1516
rpassword = "7.2.0"
1617
serde = { version = "1.0.156", features = ["derive"] }

cli/src/models.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::util;
22

33
use anyhow::Context;
4+
use regex::Regex;
45
use std::ffi::OsStr;
56
use std::fs;
67
use std::path::{Path, PathBuf};
@@ -225,10 +226,16 @@ impl ControlFileRef {
225226

226227
// Name of the extension. Used in the `create extesnion <extension_name>`
227228
fn extension_name(&self) -> anyhow::Result<String> {
228-
self.filename
229+
let name_regex = Regex::new(r"^[A-z][A-z0-9\_]{2,32}$").expect("regex is valid");
230+
let name = self
231+
.filename
229232
.strip_suffix(".control")
230233
.context("failed to read extension name from control file")
231-
.map(str::to_string)
234+
.map(str::to_string)?;
235+
if !name_regex.is_match(&name) {
236+
return Err(anyhow::anyhow!("extension name must begin with an alphabet, contain only alphanumeric characters or `_` and should be between 2 and 32 characters long."));
237+
}
238+
Ok(name)
232239
}
233240

234241
// A comment (any string) about the extension. The comment is applied when initially creating
@@ -264,7 +271,9 @@ impl ControlFileRef {
264271
return self.read_control_line_value(line);
265272
}
266273
}
267-
Err(anyhow::anyhow!("default version is required"))
274+
Err(anyhow::anyhow!(
275+
"`default_version` in control file is required"
276+
))
268277
}
269278

270279
fn read_control_line_value(&self, line: &str) -> anyhow::Result<String> {

0 commit comments

Comments
 (0)