Skip to content

Commit 330a477

Browse files
committed
improve a few more error messages
1 parent 57d2fc2 commit 330a477

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

cli/src/commands/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub async fn publish(
4545
}
4646
}
4747

48+
if num_published == 0 {
49+
return Err(anyhow::anyhow!("No valid script file (.sql) found."));
50+
}
51+
4852
for upgrade_file in &payload.upgrade_files {
4953
let request =
5054
create_publich_package_upgrade_request(&payload.metadata.extension_name, upgrade_file);

cli/src/models.rs

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

33
use anyhow::Context;
4-
use regex::Regex;
54
use std::ffi::OsStr;
65
use std::fs;
76
use std::path::{Path, PathBuf};
@@ -147,7 +146,7 @@ impl Payload {
147146

148147
if !util::is_valid_extension_name(&extension_name) {
149148
return Err(anyhow::anyhow!(
150-
"invalid extension name detected {}",
149+
"Invalid extension name detected: {}. It must begin with an alphabet, contain only alphanumeric characters or `_` and should be between 2 and 32 characters long.",
151150
extension_name
152151
));
153152
}
@@ -226,16 +225,10 @@ impl ControlFileRef {
226225

227226
// Name of the extension. Used in the `create extesnion <extension_name>`
228227
fn extension_name(&self) -> anyhow::Result<String> {
229-
let name_regex = Regex::new(r"^[A-z][A-z0-9\_]{2,32}$").expect("regex is valid");
230-
let name = self
231-
.filename
228+
self.filename
232229
.strip_suffix(".control")
233230
.context("failed to read extension name from control file")
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)
231+
.map(str::to_string)
239232
}
240233

241234
// A comment (any string) about the extension. The comment is applied when initially creating

cli/src/util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Context;
2+
use regex::Regex;
23
use sqlx::postgres::PgConnection;
34
use sqlx::Connection;
45
use std::fs::{File, OpenOptions};
@@ -10,8 +11,9 @@ pub async fn get_connection(connection_str: &str) -> anyhow::Result<PgConnection
1011
.context("Failed to establish PostgreSQL connection")
1112
}
1213

13-
pub fn is_valid_extension_name(_name: &str) -> bool {
14-
true
14+
pub fn is_valid_extension_name(name: &str) -> bool {
15+
let name_regex = Regex::new(r"^[A-z][A-z0-9\_]{2,32}$").expect("regex is valid");
16+
name_regex.is_match(name)
1517
}
1618

1719
pub fn is_valid_version(_version: &str) -> bool {

0 commit comments

Comments
 (0)