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

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

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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/target/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`") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a nicer way to match on the specific error thrown by serde when the #[serde(deny_unknown_fields)] condition is triggered, I'm all ears!

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/target/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