Skip to main content

baken_export/
error.rs

1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5/// The searched paths, or a plain note when there was nowhere to look: no
6/// rekordbox directory exists on this machine, and on Linux none ever can.
7fn searched_paths(paths: &[PathBuf]) -> String {
8    if paths.is_empty() {
9        return "nothing; this machine has no rekordbox directory to look in".into();
10    }
11    paths
12        .iter()
13        .map(|p| p.display().to_string())
14        .collect::<Vec<_>>()
15        .join(", ")
16}
17
18#[derive(Debug, thiserror::Error)]
19pub enum Error {
20    #[error("My Settings not found (MYSETTING.DAT, MYSETTING2.DAT, DJMMYSETTING.DAT, DEVSETTING.DAT). Searched: {}. Open rekordbox Preferences > DJ System > My Settings once so rekordbox writes them, or pass --settings-dir at a directory holding the four files; the PIONEER folder of any stick rekordbox exported has them.", searched_paths(searched))]
21    SettingsNotFound { searched: Vec<PathBuf> },
22
23    #[error("Playlist not found: {0}")]
24    PlaylistNotFound(String),
25
26    #[error("Playlist '{path}' is not a TrackID-referenced playlist (KeyType={key_type}); only KeyType=\"0\" playlists can be exported")]
27    UnsupportedPlaylistType { path: String, key_type: String },
28
29    #[error("No exportable playlists selected")]
30    NoPlaylists,
31
32    #[error("No rekordbox analysis files found. Searched: {}. expressport copies the waveforms rekordbox analysed and cannot compute them from the XML, so every track needs its .DAT/.EXT in rekordbox's PIONEER/USBANLZ directory; pass --anlz-dir if it is somewhere this did not look, or --generate-analysis to compute the waveforms from the audio.", searched_paths(searched))]
33    NoAnlzRoot { searched: Vec<PathBuf> },
34
35    #[error("None of the selected tracks can be exported (missing source files or analysis)")]
36    NothingToExport,
37
38    #[error("Device path is not a directory: {}", .0.display())]
39    DeviceNotFound(PathBuf),
40
41    #[error("operation cancelled")]
42    Cancelled,
43
44    #[error(transparent)]
45    Io(#[from] std::io::Error),
46
47    #[error(transparent)]
48    Other(#[from] anyhow::Error),
49}