Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Provide helpful error when user accidentally puts kv-namespace inform…
Browse files Browse the repository at this point in the history
…ation under [site] (#937)

* Provide helpful error when user accidentally puts kv-namespace information under [site]

* improve error messaging
  • Loading branch information
gabbifish authored and ashleymichal committed Dec 12, 2019
1 parent 5ea8de9 commit 2991bf9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ openssl = { version = '0.10.11', optional = true }
reqwest = "0.9.18"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.39"
toml = "0.5.0"
toml = "0.5.5"
uuid = "0.7"
which = "2.0.1"
rand = "0.6.5"
Expand Down
13 changes: 12 additions & 1 deletion src/settings/toml/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct Manifest {
pub zone_id: Option<String>,
pub webpack_config: Option<String>,
pub private: Option<bool>,
// TODO: maybe one day, serde toml support will allow us to serialize sites
// as a TOML inline table (this would prevent confusion with environments too!)
pub site: Option<Site>,
#[serde(rename = "kv-namespaces")]
pub kv_namespaces: Option<Vec<KvNamespace>>,
Expand All @@ -46,7 +48,16 @@ impl Manifest {
pub fn new(config_path: &Path) -> Result<Self, failure::Error> {
let config = read_config(config_path)?;

let manifest: Manifest = config.try_into()?;
let manifest: Manifest = match config.try_into() {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("unknown field `kv-namespaces`") {
failure::bail!("kv-namespaces should not live under the [site] table in wrangler.toml; please move it above [site].")
} else {
failure::bail!(e)
}
}
};

check_for_duplicate_names(&manifest)?;

Expand Down
1 change: 1 addition & 0 deletions src/settings/toml/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::commands::generate::run_generate;
const SITE_ENTRY_POINT: &str = "workers-site";

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Site {
pub bucket: PathBuf,
#[serde(rename = "entry-point")]
Expand Down

0 comments on commit 2991bf9

Please sign in to comment.