From 70e28116300277307ecfaedfc60c1d8d706067a7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 14:04:36 +0200 Subject: [PATCH 1/7] add validation that partitions don't overlap --- espflash/src/error.rs | 66 +++++++++++++++++++++++---------- espflash/src/partition_table.rs | 41 ++++++++++++++++---- 2 files changed, 81 insertions(+), 26 deletions(-) diff --git a/espflash/src/error.rs b/espflash/src/error.rs index b2da0bac..99a4b072 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -1,7 +1,6 @@ use crate::flasher::Command; use crate::image_format::ImageFormatId; use crate::Chip; -use csv::Position; use miette::{Diagnostic, SourceOffset, SourceSpan}; use slip_codec::Error as SlipError; use std::fmt::{Display, Formatter}; @@ -266,15 +265,25 @@ impl ResultExt for Result { } } +#[derive(Debug, Error, Diagnostic)] +pub enum PartitionTableError { + #[error(transparent)] + #[diagnostic(transparent)] + CSV(#[from] CSVError), + #[error(transparent)] + #[diagnostic(transparent)] + Overlapping(#[from] OverlappingPartitionsError), +} + #[derive(Debug, Error, Diagnostic)] #[error("Malformed partition table")] #[diagnostic( - code(espflash::mallformed_partition_table), + code(espflash::partition_table::mallformed), help("See the espressif documentation for information on the partition table format: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables") )] -pub struct PartitionTableError { +pub struct CSVError { #[source_code] source: String, #[label("{}", self.hint)] @@ -284,12 +293,12 @@ pub struct PartitionTableError { error: csv::Error, } -impl PartitionTableError { +impl CSVError { pub fn new(error: csv::Error, source: String) -> Self { - let err_pos = match error.kind() { - csv::ErrorKind::Deserialize { pos: Some(pos), .. } => pos.clone(), - csv::ErrorKind::UnequalLengths { pos: Some(pos), .. } => pos.clone(), - _ => Position::new(), + let err_line = match error.kind() { + csv::ErrorKind::Deserialize { pos: Some(pos), .. } => pos.line(), + csv::ErrorKind::UnequalLengths { pos: Some(pos), .. } => pos.line(), + _ => 0, }; let hint = match error.kind() { csv::ErrorKind::Deserialize { err, .. } => err.to_string(), @@ -302,16 +311,9 @@ impl PartitionTableError { _ => String::new(), }; - // since csv doesn't give us the position in the line the error occurs, we highlight the entire line - let line_length = source - .lines() - .nth(err_pos.line() as usize - 1) - .unwrap() - .len() - .into(); - let err_span = SourceSpan::new(pos_to_offset(err_pos), line_length); + let err_span = line_to_span(&source, err_line as usize); - PartitionTableError { + CSVError { source, err_span, hint, @@ -320,8 +322,34 @@ impl PartitionTableError { } } -fn pos_to_offset(pos: Position) -> SourceOffset { - (pos.byte() as usize).into() +/// since csv doesn't give us the position in the line the error occurs, we highlight the entire line +/// +/// line starts at 1 +fn line_to_span(source: &str, line: usize) -> SourceSpan { + let line_length = source.lines().nth(line - 1).unwrap().len().into(); + SourceSpan::new(SourceOffset::from_location(source, line, 2), line_length) +} + +#[derive(Debug, Error, Diagnostic)] +#[error("Overlapping partitions")] +#[diagnostic(code(espflash::partition_table::overlapping))] +pub struct OverlappingPartitionsError { + #[source_code] + source_code: String, + #[label("This partition")] + partition1_span: SourceSpan, + #[label("Overlaps with this partition")] + partition2_span: SourceSpan, +} + +impl OverlappingPartitionsError { + pub fn new(source: &str, partition1_line: usize, partition2_line: usize) -> Self { + OverlappingPartitionsError { + source_code: source.into(), + partition1_span: line_to_span(&source, partition1_line), + partition2_span: line_to_span(&source, partition2_line), + } + } } #[derive(Debug, Error)] diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 40c388b7..86a39d02 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -2,12 +2,12 @@ use md5::{Context, Digest}; use regex::Regex; use serde::{Deserialize, Deserializer}; -use crate::error::PartitionTableError; +use crate::error::{CSVError, OverlappingPartitionsError, PartitionTableError}; +use std::cmp::{max, min}; use std::io::Write; const MAX_PARTITION_LENGTH: usize = 0xC00; const PARTITION_TABLE_SIZE: usize = 0x1000; -const MAX_PARTITION_TABLE_ENTRIES: usize = 95; #[derive(Copy, Clone, Debug, Deserialize)] #[repr(u8)] @@ -147,14 +147,20 @@ impl PartitionTable { .trim(csv::Trim::All) .from_reader(data.trim().as_bytes()); - let mut partitions = Vec::with_capacity(MAX_PARTITION_TABLE_ENTRIES); - for partition in reader.deserialize() { - let partition: Partition = - partition.map_err(|e| PartitionTableError::new(e, data.clone()))?; + let mut partitions = Vec::with_capacity(data.lines().count()); + for record in reader.records() { + let record = record.map_err(|e| CSVError::new(e, data.clone()))?; + let position = record.position(); + let mut partition: Partition = record + .deserialize(None) + .map_err(|e| CSVError::new(e, data.clone()))?; + partition.line = position.map(|pos| pos.line() as usize); partitions.push(partition); } - Ok(Self { partitions }) + let table = Self { partitions }; + table.validate(&data)?; + Ok(table) } pub fn to_bytes(&self) -> Vec { @@ -184,6 +190,20 @@ impl PartitionTable { Ok(()) } + + fn validate(&self, source: &str) -> Result<(), PartitionTableError> { + for partition1 in &self.partitions { + for partition2 in &self.partitions { + if let (Some(line1), Some(line2)) = (&partition1.line, &partition2.line) { + if line1 != line2 && partition1.overlaps(partition2) { + return Err(OverlappingPartitionsError::new(source, *line1, *line2).into()); + } + } + } + } + + Ok(()) + } } const PARTITION_SIZE: usize = 32; @@ -199,6 +219,8 @@ struct Partition { #[serde(deserialize_with = "deserialize_partition_offset_or_size")] size: u32, flags: Option, + #[serde(skip)] + line: Option, } impl Partition { @@ -219,6 +241,7 @@ impl Partition { offset, size, flags, + line: None, } } @@ -242,6 +265,10 @@ impl Partition { Ok(()) } + + fn overlaps(&self, other: &Partition) -> bool { + max(self.offset, other.offset) < min(self.offset + self.size, other.offset + other.size) + } } fn deserialize_partition_name<'de, D>(deserializer: D) -> Result From fcd113c3b9c75abb98c1ec1e17e76505c799286f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 14:17:16 +0200 Subject: [PATCH 2/7] add error when 2 partitions have the same name or type --- espflash/src/error.rs | 34 ++++++++++++++++++++++++++++++++- espflash/src/partition_table.rs | 30 +++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/espflash/src/error.rs b/espflash/src/error.rs index 99a4b072..cae84fb4 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -273,6 +273,9 @@ pub enum PartitionTableError { #[error(transparent)] #[diagnostic(transparent)] Overlapping(#[from] OverlappingPartitionsError), + #[error(transparent)] + #[diagnostic(transparent)] + Duplicate(#[from] DuplicatePartitionsError), } #[derive(Debug, Error, Diagnostic)] @@ -338,7 +341,7 @@ pub struct OverlappingPartitionsError { source_code: String, #[label("This partition")] partition1_span: SourceSpan, - #[label("Overlaps with this partition")] + #[label("overlaps with this partition")] partition2_span: SourceSpan, } @@ -352,6 +355,35 @@ impl OverlappingPartitionsError { } } +#[derive(Debug, Error, Diagnostic)] +#[error("Duplicate partitions")] +#[diagnostic(code(espflash::partition_table::duplicate))] +pub struct DuplicatePartitionsError { + #[source_code] + source_code: String, + #[label("This partition")] + partition1_span: SourceSpan, + #[label("has the same {} as this partition", self.ty)] + partition2_span: SourceSpan, + ty: &'static str, +} + +impl DuplicatePartitionsError { + pub fn new( + source: &str, + partition1_line: usize, + partition2_line: usize, + ty: &'static str, + ) -> Self { + DuplicatePartitionsError { + source_code: source.into(), + partition1_span: line_to_span(&source, partition1_line), + partition2_span: line_to_span(&source, partition2_line), + ty, + } + } +} + #[derive(Debug, Error)] #[error("{0}")] pub struct ElfError(&'static str); diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 86a39d02..0e42bfc6 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -2,7 +2,9 @@ use md5::{Context, Digest}; use regex::Regex; use serde::{Deserialize, Deserializer}; -use crate::error::{CSVError, OverlappingPartitionsError, PartitionTableError}; +use crate::error::{ + CSVError, DuplicatePartitionsError, OverlappingPartitionsError, PartitionTableError, +}; use std::cmp::{max, min}; use std::io::Write; @@ -18,7 +20,7 @@ pub enum Type { Data = 0x01, } -#[derive(Copy, Clone, Debug, Deserialize)] +#[derive(Copy, Clone, Debug, Deserialize, PartialEq)] #[repr(u8)] #[allow(dead_code)] #[serde(rename_all = "lowercase")] @@ -59,7 +61,7 @@ pub enum AppType { Test = 0x20, } -#[derive(Copy, Clone, Debug, Deserialize)] +#[derive(Copy, Clone, Debug, Deserialize, PartialEq)] #[repr(u8)] #[allow(dead_code)] #[serde(rename_all = "lowercase")] @@ -76,7 +78,7 @@ pub enum DataType { Spiffs = 0x82, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, PartialEq)] #[allow(dead_code)] #[serde(untagged)] pub enum SubType { @@ -195,8 +197,24 @@ impl PartitionTable { for partition1 in &self.partitions { for partition2 in &self.partitions { if let (Some(line1), Some(line2)) = (&partition1.line, &partition2.line) { - if line1 != line2 && partition1.overlaps(partition2) { - return Err(OverlappingPartitionsError::new(source, *line1, *line2).into()); + if line1 != line2 { + if partition1.overlaps(partition2) { + return Err( + OverlappingPartitionsError::new(source, *line1, *line2).into() + ); + } + if partition1.name == partition2.name { + return Err(DuplicatePartitionsError::new( + source, *line1, *line2, "name", + ) + .into()); + } + if partition1.sub_type == partition2.sub_type { + return Err(DuplicatePartitionsError::new( + source, *line1, *line2, "sub-type", + ) + .into()); + } } } } From 68d86efccd01f72c91401c94ec445cafd64feea1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 14:57:57 +0200 Subject: [PATCH 3/7] add check that the subtype is valid for the partition type --- espflash/Cargo.toml | 1 + espflash/src/error.rs | 30 +++++++++++ espflash/src/partition_table.rs | 88 +++++++++++++++++++++++++++++---- 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index ec2122c3..68732056 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -26,6 +26,7 @@ slip-codec = "0.2.4" thiserror = "1.0.20" xmas-elf = "0.8.0" serde = { version = "1.0", features = ["derive"] } +serde_plain = "1" toml = "0.5" directories-next = "2.0.0" color-eyre = "0.5" diff --git a/espflash/src/error.rs b/espflash/src/error.rs index cae84fb4..c835b135 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -1,5 +1,6 @@ use crate::flasher::Command; use crate::image_format::ImageFormatId; +use crate::partition_table::{SubType, Type}; use crate::Chip; use miette::{Diagnostic, SourceOffset, SourceSpan}; use slip_codec::Error as SlipError; @@ -276,6 +277,9 @@ pub enum PartitionTableError { #[error(transparent)] #[diagnostic(transparent)] Duplicate(#[from] DuplicatePartitionsError), + #[error(transparent)] + #[diagnostic(transparent)] + InvalidSubType(#[from] InvalidSubTypeError), } #[derive(Debug, Error, Diagnostic)] @@ -384,6 +388,32 @@ impl DuplicatePartitionsError { } } +#[derive(Debug, Error, Diagnostic)] +#[error("Invalid subtype for type")] +#[diagnostic( + code(espflash::partition_table::invalid_type), + help("'{}' supports the following subtypes: {}", self.ty, self.ty.subtype_hint()) +)] +pub struct InvalidSubTypeError { + #[source_code] + source_code: String, + #[label("'{}' is not a valid subtype for '{}'", self.sub_type, self.ty)] + span: SourceSpan, + ty: Type, + sub_type: SubType, +} + +impl InvalidSubTypeError { + pub fn new(source: &str, line: usize, ty: Type, sub_type: SubType) -> Self { + InvalidSubTypeError { + source_code: source.into(), + span: line_to_span(&source, line), + ty, + sub_type, + } + } +} + #[derive(Debug, Error)] #[error("{0}")] pub struct ElfError(&'static str); diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 0e42bfc6..71691d6f 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -1,17 +1,19 @@ -use md5::{Context, Digest}; -use regex::Regex; -use serde::{Deserialize, Deserializer}; - use crate::error::{ - CSVError, DuplicatePartitionsError, OverlappingPartitionsError, PartitionTableError, + CSVError, DuplicatePartitionsError, InvalidSubTypeError, OverlappingPartitionsError, + PartitionTableError, }; +use md5::{Context, Digest}; +use regex::Regex; +use serde::{Deserialize, Deserializer, Serialize}; use std::cmp::{max, min}; +use std::fmt::Write as _; +use std::fmt::{Display, Formatter}; use std::io::Write; const MAX_PARTITION_LENGTH: usize = 0xC00; const PARTITION_TABLE_SIZE: usize = 0x1000; -#[derive(Copy, Clone, Debug, Deserialize)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[repr(u8)] #[allow(dead_code)] #[serde(rename_all = "lowercase")] @@ -20,7 +22,46 @@ pub enum Type { Data = 0x01, } -#[derive(Copy, Clone, Debug, Deserialize, PartialEq)] +impl Type { + pub fn subtype_hint(&self) -> String { + match self { + Type::App => "'factory', 'ota_0' trough 'ota_15' and 'test'".into(), + Type::Data => { + let types = [ + DataType::Ota, + DataType::Phy, + DataType::Nvs, + DataType::CoreDump, + DataType::NvsKeys, + DataType::EFuse, + DataType::EspHttpd, + DataType::Fat, + DataType::Spiffs, + ]; + + let mut out = format!("'{}'", serde_plain::to_string(&types[0]).unwrap()); + for ty in &types[1..types.len() - 2] { + let ser = serde_plain::to_string(&ty).unwrap(); + write!(&mut out, ", '{}'", ser).unwrap(); + } + + let ser = serde_plain::to_string(&types[types.len() - 1]).unwrap(); + write!(&mut out, " and '{}'", ser).unwrap(); + + out + } + } + } +} + +impl Display for Type { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let ser = serde_plain::to_string(self).unwrap(); + write!(f, "{}", ser) + } +} + +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[repr(u8)] #[allow(dead_code)] #[serde(rename_all = "lowercase")] @@ -61,7 +102,7 @@ pub enum AppType { Test = 0x20, } -#[derive(Copy, Clone, Debug, Deserialize, PartialEq)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] #[repr(u8)] #[allow(dead_code)] #[serde(rename_all = "lowercase")] @@ -78,7 +119,7 @@ pub enum DataType { Spiffs = 0x82, } -#[derive(Debug, Deserialize, PartialEq)] +#[derive(Debug, Deserialize, PartialEq, Copy, Clone)] #[allow(dead_code)] #[serde(untagged)] pub enum SubType { @@ -86,6 +127,17 @@ pub enum SubType { Data(DataType), } +impl Display for SubType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let ser = match self { + SubType::App(sub) => serde_plain::to_string(sub), + SubType::Data(sub) => serde_plain::to_string(sub), + } + .unwrap(); + write!(f, "{}", ser) + } +} + impl SubType { fn as_u8(&self) -> u8 { match self { @@ -194,6 +246,24 @@ impl PartitionTable { } fn validate(&self, source: &str) -> Result<(), PartitionTableError> { + for partition in &self.partitions { + if let Some(line) = &partition.line { + let expected_type = match partition.sub_type { + SubType::App(_) => Type::App, + SubType::Data(_) => Type::Data, + }; + if expected_type != partition.ty { + return Err(InvalidSubTypeError::new( + source, + *line, + partition.ty, + partition.sub_type, + ) + .into()); + } + } + } + for partition1 in &self.partitions { for partition2 in &self.partitions { if let (Some(line1), Some(line2)) = (&partition1.line, &partition2.line) { From 88fef267f94c8571d431b6555dea36f2a6d9d017 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 15:08:32 +0200 Subject: [PATCH 4/7] better error messages for invalid partition subtype --- espflash/src/error.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/espflash/src/error.rs b/espflash/src/error.rs index c835b135..343924e8 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -286,9 +286,9 @@ pub enum PartitionTableError { #[error("Malformed partition table")] #[diagnostic( code(espflash::partition_table::mallformed), - help("See the espressif documentation for information on the partition table format: + help("{}See the espressif documentation for information on the partition table format: -https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables") +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables", self.help) )] pub struct CSVError { #[source_code] @@ -298,6 +298,7 @@ pub struct CSVError { hint: String, #[source] error: csv::Error, + help: String, } impl CSVError { @@ -307,7 +308,7 @@ impl CSVError { csv::ErrorKind::UnequalLengths { pos: Some(pos), .. } => pos.line(), _ => 0, }; - let hint = match error.kind() { + let mut hint = match error.kind() { csv::ErrorKind::Deserialize { err, .. } => err.to_string(), csv::ErrorKind::UnequalLengths { expected_len, len, .. @@ -317,6 +318,20 @@ impl CSVError { ), _ => String::new(), }; + let mut help = String::new(); + + // string matching is fragile but afaik there is no better way in this case + // and if it does break the error is still not bad + if hint == "data did not match any variant of untagged enum SubType" { + hint = "Unknown sub-type".into(); + help = format!( + "the following sub-types are supported: + {} for data partitions + {} for app partitions\n\n", + Type::Data.subtype_hint(), + Type::App.subtype_hint() + ) + } let err_span = line_to_span(&source, err_line as usize); @@ -325,6 +340,7 @@ impl CSVError { err_span, hint, error, + help, } } } From e4e200de25485422ee7c99d19dd18958a3ef8736 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 15:22:00 +0200 Subject: [PATCH 5/7] add check that app partitions are aligned to 64k --- espflash/src/error.rs | 22 ++++++++++++++++++++++ espflash/src/partition_table.rs | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/espflash/src/error.rs b/espflash/src/error.rs index 343924e8..4b3f486b 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -280,6 +280,9 @@ pub enum PartitionTableError { #[error(transparent)] #[diagnostic(transparent)] InvalidSubType(#[from] InvalidSubTypeError), + #[error(transparent)] + #[diagnostic(transparent)] + UnalignedPartitionError(#[from] UnalignedPartitionError), } #[derive(Debug, Error, Diagnostic)] @@ -430,6 +433,25 @@ impl InvalidSubTypeError { } } +#[derive(Debug, Error, Diagnostic)] +#[error("Unaligned partition")] +#[diagnostic(code(espflash::partition_table::unaligned))] +pub struct UnalignedPartitionError { + #[source_code] + source_code: String, + #[label("App partition is not aligned to 64k (0x10000)")] + span: SourceSpan, +} + +impl UnalignedPartitionError { + pub fn new(source: &str, line: usize) -> Self { + UnalignedPartitionError { + source_code: source.into(), + span: line_to_span(&source, line), + } + } +} + #[derive(Debug, Error)] #[error("{0}")] pub struct ElfError(&'static str); diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 71691d6f..baba510c 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -1,6 +1,6 @@ use crate::error::{ CSVError, DuplicatePartitionsError, InvalidSubTypeError, OverlappingPartitionsError, - PartitionTableError, + PartitionTableError, UnalignedPartitionError, }; use md5::{Context, Digest}; use regex::Regex; @@ -9,6 +9,7 @@ use std::cmp::{max, min}; use std::fmt::Write as _; use std::fmt::{Display, Formatter}; use std::io::Write; +use std::ops::Rem; const MAX_PARTITION_LENGTH: usize = 0xC00; const PARTITION_TABLE_SIZE: usize = 0x1000; @@ -261,6 +262,9 @@ impl PartitionTable { ) .into()); } + if partition.ty == Type::App && partition.offset.rem(0x10000) != 0 { + return Err(UnalignedPartitionError::new(source, *line).into()); + } } } From 7b48f24b26693d6bdb29d3c93fa26dc8957137e1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 15:25:29 +0200 Subject: [PATCH 6/7] fix typo --- cargo-espflash/src/main.rs | 7 +++++-- espflash/src/partition_table.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 47789a7c..9fc6c1a0 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -174,8 +174,11 @@ fn main() -> Result<()> { .or_else(|| metadata.partition_table.as_deref()) { let path = fs::canonicalize(path).into_diagnostic()?; - let data = fs::read_to_string(path).into_diagnostic()?; - let table = PartitionTable::try_from_str(data)?; + let data = fs::read_to_string(path) + .into_diagnostic() + .wrap_err("Failed to open partition table")?; + let table = + PartitionTable::try_from_str(data).wrap_err("Failed to parse partition table")?; Some(table) } else { None diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index baba510c..8acb2c65 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -26,7 +26,7 @@ pub enum Type { impl Type { pub fn subtype_hint(&self) -> String { match self { - Type::App => "'factory', 'ota_0' trough 'ota_15' and 'test'".into(), + Type::App => "'factory', 'ota_0' through 'ota_15' and 'test'".into(), Type::Data => { let types = [ DataType::Ota, From dd61da1bc84cdd84300f400126a30a264283eb4e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 1 Oct 2021 15:41:45 +0200 Subject: [PATCH 7/7] clippy --- espflash/src/error.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/espflash/src/error.rs b/espflash/src/error.rs index 4b3f486b..2bfa5562 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -270,7 +270,7 @@ impl ResultExt for Result { pub enum PartitionTableError { #[error(transparent)] #[diagnostic(transparent)] - CSV(#[from] CSVError), + Csv(#[from] CSVError), #[error(transparent)] #[diagnostic(transparent)] Overlapping(#[from] OverlappingPartitionsError), @@ -372,8 +372,8 @@ impl OverlappingPartitionsError { pub fn new(source: &str, partition1_line: usize, partition2_line: usize) -> Self { OverlappingPartitionsError { source_code: source.into(), - partition1_span: line_to_span(&source, partition1_line), - partition2_span: line_to_span(&source, partition2_line), + partition1_span: line_to_span(source, partition1_line), + partition2_span: line_to_span(source, partition2_line), } } } @@ -400,8 +400,8 @@ impl DuplicatePartitionsError { ) -> Self { DuplicatePartitionsError { source_code: source.into(), - partition1_span: line_to_span(&source, partition1_line), - partition2_span: line_to_span(&source, partition2_line), + partition1_span: line_to_span(source, partition1_line), + partition2_span: line_to_span(source, partition2_line), ty, } } @@ -426,7 +426,7 @@ impl InvalidSubTypeError { pub fn new(source: &str, line: usize, ty: Type, sub_type: SubType) -> Self { InvalidSubTypeError { source_code: source.into(), - span: line_to_span(&source, line), + span: line_to_span(source, line), ty, sub_type, } @@ -447,7 +447,7 @@ impl UnalignedPartitionError { pub fn new(source: &str, line: usize) -> Self { UnalignedPartitionError { source_code: source.into(), - span: line_to_span(&source, line), + span: line_to_span(source, line), } } }