liboxen 0.46.9

Oxen is a fast, unstructured data version control, to help version large machine learning datasets written in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//! Errors for the oxen library
//!
//! Enumeration for all errors that can occur in the oxen library
//!

use duckdb::arrow::error::ArrowError;
use std::io;
use std::num::ParseIntError;
use std::path::Path;
use std::path::PathBuf;
use std::path::StripPrefixError;
use tokio::task::JoinError;

use crate::model::RepoNew;
use crate::model::Schema;
use crate::model::Workspace;
use crate::model::{Commit, ParsedResource};

pub mod path_buf_error;
pub mod string_error;

pub use crate::error::path_buf_error::PathBufError;
pub use crate::error::string_error::StringError;

pub const HEAD_NOT_FOUND: &str = "HEAD not found";

pub const EMAIL_AND_NAME_NOT_FOUND: &str = "oxen not configured, set email and name with:\n\noxen config --name YOUR_NAME --email YOUR_EMAIL\n";

pub const AUTH_TOKEN_NOT_FOUND: &str = "oxen authentication token not found, obtain one from your administrator and configure with:\n\noxen config --auth <HOST> <TOKEN>\n";

#[derive(thiserror::Error, Debug)]
pub enum OxenError {
    // User
    #[error("{0}")]
    UserConfigNotFound(Box<StringError>),

    // Repo
    #[error("Repository '{0}' not found")]
    RepoNotFound(Box<RepoNew>),
    #[error("No oxen repository found at {0}")]
    LocalRepoNotFound(Box<PathBufError>),
    #[error("Repository '{0}' already exists")]
    RepoAlreadyExists(Box<RepoNew>),
    #[error("Repository already exists at destination: {0}")]
    RepoAlreadyExistsAtDestination(Box<StringError>),
    #[error("Invalid repository or namespace name '{0}'. Must match [a-zA-Z0-9][a-zA-Z0-9_.-]+")]
    InvalidRepoName(StringError),

    // Fork
    #[error("{0}")]
    ForkStatusNotFound(StringError),

    // Remotes
    #[error("Remote repository not found: {0}")]
    RemoteRepoNotFound(Box<StringError>),
    #[error("{0}")]
    RemoteAheadOfLocal(StringError),
    #[error("{0}")]
    IncompleteLocalHistory(StringError),
    #[error("{0}")]
    RemoteBranchLocked(StringError),
    #[error("{0}")]
    UpstreamMergeConflict(StringError),

    // Branches/Commits
    #[error("{0}")]
    BranchNotFound(Box<StringError>),
    #[error("Revision not found: {0}")]
    RevisionNotFound(Box<StringError>),
    #[error("Root commit does not match: {0}")]
    RootCommitDoesNotMatch(Box<Commit>),
    #[error("{0}")]
    NothingToCommit(StringError),
    #[error("{0}")]
    NoCommitsFound(StringError),
    #[error("{0}")]
    HeadNotFound(StringError),

    // Workspaces
    #[error("Workspace not found: {0}")]
    WorkspaceNotFound(Box<StringError>),
    #[error("No queryable workspace found")]
    QueryableWorkspaceNotFound(),
    #[error("Workspace is behind: {0}")]
    WorkspaceBehind(Box<Workspace>),

    // Resources (paths, uris, etc.)
    #[error("Resource not found: {0}")]
    ResourceNotFound(StringError),
    #[error("Path does not exist: {0}")]
    PathDoesNotExist(Box<PathBufError>),
    #[error("Resource not found: {0}")]
    ParsedResourceNotFound(Box<PathBufError>),

    // Versioning
    #[error("{0}")]
    MigrationRequired(StringError),
    #[error("{0}")]
    OxenUpdateRequired(StringError),
    #[error("Invalid version: {0}")]
    InvalidVersion(StringError),

    // Entry
    #[error("{0}")]
    CommitEntryNotFound(StringError),

    // Schema
    #[error("Invalid schema: {0}")]
    InvalidSchema(Box<Schema>),
    #[error("Incompatible schemas: {0}")]
    IncompatibleSchemas(Box<Schema>),
    #[error("{0}")]
    InvalidFileType(StringError),
    #[error("{0}")]
    ColumnNameAlreadyExists(StringError),
    #[error("{0}")]
    ColumnNameNotFound(StringError),
    #[error("{0}")]
    UnsupportedOperation(StringError),

    // Metadata
    #[error("{0}")]
    ImageMetadataParseError(StringError),
    #[error("{0}")]
    ThumbnailingNotEnabled(StringError),

    // SQL
    #[error("SQL parse error: {0}")]
    SQLParseError(StringError),
    #[error("{0}")]
    NoRowsFound(StringError),

    // CLI Interaction
    #[error("{0}")]
    OperationCancelled(StringError),

    // fs / io
    #[error("{0}")]
    StripPrefixError(StringError),

    // Dataframe Errors
    #[error("{0}")]
    DataFrameError(StringError),

    // File Import Error
    #[error("{0}")]
    ImportFileError(StringError),

    // External Library Errors
    #[error("{0}")]
    IO(#[from] io::Error),
    #[error("Authentication failed: {0}")]
    Authentication(StringError),
    #[error("{0}")]
    ArrowError(#[from] ArrowError),
    #[error("{0}")]
    BinCodeError(#[from] bincode::Error),
    #[error("Configuration error: {0}")]
    TomlSer(#[from] toml::ser::Error),
    #[error("Configuration error: {0}")]
    TomlDe(#[from] toml::de::Error),
    #[error("Invalid URI: {0}")]
    URI(#[from] http::uri::InvalidUri),
    #[error("Invalid URL: {0}")]
    URL(#[from] url::ParseError),
    #[error("JSON error: {0}")]
    JSON(#[from] serde_json::Error),
    #[error("Network error: {0}")]
    HTTP(#[from] reqwest::Error),
    #[error("UTF-8 encoding error: {0}")]
    UTF8Error(#[from] std::str::Utf8Error),
    #[error("Database error: {0}")]
    DB(#[from] rocksdb::Error),
    #[error("Query error: {0}")]
    DUCKDB(#[from] duckdb::Error),
    #[error("Environment variable error: {0}")]
    ENV(#[from] std::env::VarError),
    #[error("Image processing error: {0}")]
    ImageError(#[from] image::ImageError),
    #[error("Redis error: {0}")]
    RedisError(#[from] redis::RedisError),
    #[error("Connection pool error: {0}")]
    R2D2Error(#[from] r2d2::Error),
    #[error("Directory traversal error: {0}")]
    JwalkError(#[from] jwalk::Error),
    #[error("Pattern error: {0}")]
    PatternError(#[from] glob::PatternError),
    #[error("Glob error: {0}")]
    GlobError(#[from] glob::GlobError),
    #[error("DataFrame error: {0}")]
    PolarsError(#[from] polars::prelude::PolarsError),
    #[error("Invalid integer: {0}")]
    ParseIntError(#[from] ParseIntError),
    #[error("Decode error: {0}")]
    RmpDecodeError(#[from] rmp_serde::decode::Error),

    // Fallback
    #[error("{0}")]
    Basic(StringError),
}

impl OxenError {
    /// Returns a user-facing hint for this error, or None if none applies.
    pub fn hint(&self) -> Option<String> {
        use OxenError::*;
        use std::io::ErrorKind::PermissionDenied;

        let hint = match self {
            LocalRepoNotFound(_) => "Run `oxen init` to create a new repository here.",
            Authentication(_) => {
                "Check your token with `oxen config --auth <HOST> <TOKEN>` and try again."
            }
            RemoteRepoNotFound(_) => {
                "Verify the remote URL is correct. Check your remotes with `oxen remote -v`."
            }
            BranchNotFound(_) => "List available branches with `oxen branch --all`.",
            RevisionNotFound(_) => {
                "Check available branches with `oxen branch --all` or commits with `oxen log`."
            }
            NothingToCommit(_) => "Stage changes with `oxen add <path>` before committing.",
            HeadNotFound(_) | NoCommitsFound(_) => {
                "This repository has no commits yet. Add files and create your first commit."
            }
            PathDoesNotExist(_)
            | ResourceNotFound(_)
            | ParsedResourceNotFound(_)
            | CommitEntryNotFound(_) => "Check the path and current branch with `oxen status`.",
            HTTP(req_err) => {
                if req_err.is_connect() || req_err.is_timeout() {
                    "Check your internet connection and that the remote host is reachable."
                } else if req_err.is_status() {
                    if let Some(status) = req_err.status() {
                        return Some(format!("Server returned HTTP {status}."));
                    } else {
                        return None;
                    }
                } else {
                    "Check your internet connection and remote configuration with `oxen remote -v`."
                }
            }
            IO(io_err) if io_err.kind() == PermissionDenied => {
                "Check file permissions and try again."
            }
            DB(_) | ArrowError(_) | BinCodeError(_) | RedisError(_) | R2D2Error(_)
            | RmpDecodeError(_) => {
                "This is an internal error. Run with RUST_LOG=debug for more details."
            }
            _ => return None,
        }
        .to_string();
        Some(hint)
    }

    pub fn basic_str(s: impl AsRef<str>) -> Self {
        OxenError::Basic(StringError::from(s.as_ref()))
    }

    pub fn thumbnailing_not_enabled(s: impl AsRef<str>) -> Self {
        OxenError::ThumbnailingNotEnabled(StringError::from(s.as_ref()))
    }

    pub fn authentication(s: impl AsRef<str>) -> Self {
        OxenError::Authentication(StringError::from(s.as_ref()))
    }

    pub fn migration_required(s: impl AsRef<str>) -> Self {
        OxenError::MigrationRequired(StringError::from(s.as_ref()))
    }

    pub fn invalid_version(s: impl AsRef<str>) -> Self {
        OxenError::InvalidVersion(StringError::from(s.as_ref()))
    }

    pub fn oxen_update_required(s: impl AsRef<str>) -> Self {
        OxenError::OxenUpdateRequired(StringError::from(s.as_ref()))
    }

    pub fn user_config_not_found(value: StringError) -> Self {
        OxenError::UserConfigNotFound(Box::new(value))
    }

    pub fn repo_not_found(repo: RepoNew) -> Self {
        OxenError::RepoNotFound(Box::new(repo))
    }

    pub fn file_import_error(s: impl AsRef<str>) -> Self {
        OxenError::ImportFileError(StringError::from(s.as_ref()))
    }

    pub fn remote_not_set(name: impl AsRef<str>) -> Self {
        let name = name.as_ref();
        OxenError::basic_str(format!(
            "Remote not set, you can set a remote by running:\n\noxen config --set-remote {name} <url>\n"
        ))
    }

    pub fn remote_ahead_of_local() -> Self {
        OxenError::RemoteAheadOfLocal(StringError::from(
            "\nRemote ahead of local, must pull changes. To fix run:\n\n  oxen pull\n",
        ))
    }

    pub fn upstream_merge_conflict() -> Self {
        OxenError::UpstreamMergeConflict(StringError::from(
            "\nRemote has conflicts with local branch. To fix run:\n\n  oxen pull\n\nThen resolve conflicts and commit changes.\n",
        ))
    }

    pub fn merge_conflict(desc: impl AsRef<str>) -> Self {
        OxenError::UpstreamMergeConflict(StringError::from(desc.as_ref()))
    }

    pub fn incomplete_local_history() -> Self {
        OxenError::IncompleteLocalHistory(StringError::from(
            "\nCannot push to an empty repository with an incomplete local history. To fix, pull the complete history from your remote:\n\n  oxen pull <remote> <branch> --all\n",
        ))
    }

    pub fn remote_branch_locked() -> Self {
        OxenError::RemoteBranchLocked(StringError::from(
            "\nRemote branch is locked - another push is in progress. Wait a bit before pushing again, or try pushing to a new branch.\n",
        ))
    }

    pub fn operation_cancelled() -> Self {
        OxenError::OperationCancelled(StringError::from("\nOperation cancelled.\n"))
    }

    pub fn resource_not_found(value: impl AsRef<str>) -> Self {
        OxenError::ResourceNotFound(StringError::from(value.as_ref()))
    }

    pub fn path_does_not_exist(path: impl AsRef<Path>) -> Self {
        OxenError::PathDoesNotExist(Box::new(path.as_ref().into()))
    }

    pub fn image_metadata_error(s: impl AsRef<str>) -> Self {
        OxenError::ImageMetadataParseError(StringError::from(s.as_ref()))
    }

    pub fn sql_parse_error(s: impl AsRef<str>) -> Self {
        OxenError::SQLParseError(StringError::from(s.as_ref()))
    }

    pub fn parsed_resource_not_found(resource: ParsedResource) -> Self {
        OxenError::ParsedResourceNotFound(Box::new(resource.resource.into()))
    }

    pub fn invalid_repo_name(s: impl AsRef<str>) -> Self {
        OxenError::InvalidRepoName(StringError::from(s.as_ref()))
    }

    pub fn is_auth_error(&self) -> bool {
        matches!(self, OxenError::Authentication(_))
    }

    pub fn is_not_found(&self) -> bool {
        matches!(
            self,
            OxenError::PathDoesNotExist(_)
                | OxenError::ResourceNotFound(_)
                | OxenError::RemoteRepoNotFound(_)
        )
    }

    pub fn repo_already_exists(repo: RepoNew) -> Self {
        OxenError::RepoAlreadyExists(Box::new(repo))
    }

    pub fn repo_already_exists_at_destination(value: StringError) -> Self {
        OxenError::RepoAlreadyExistsAtDestination(Box::new(value))
    }

    pub fn fork_status_not_found() -> Self {
        OxenError::ForkStatusNotFound(StringError::from("No fork status found"))
    }

    pub fn revision_not_found(value: StringError) -> Self {
        OxenError::RevisionNotFound(Box::new(value))
    }

    pub fn workspace_not_found(value: StringError) -> Self {
        OxenError::WorkspaceNotFound(Box::new(value))
    }

    pub fn workspace_behind(workspace: &Workspace) -> Self {
        OxenError::WorkspaceBehind(Box::new(workspace.clone()))
    }

    pub fn root_commit_does_not_match(commit: Commit) -> Self {
        OxenError::RootCommitDoesNotMatch(Box::new(commit))
    }

    pub fn no_commits_found() -> Self {
        OxenError::NoCommitsFound(StringError::from("\n No commits found.\n"))
    }

    pub fn local_repo_not_found(dir: impl AsRef<Path>) -> OxenError {
        OxenError::LocalRepoNotFound(Box::new(dir.as_ref().into()))
    }

    pub fn email_and_name_not_set() -> OxenError {
        OxenError::user_config_not_found(EMAIL_AND_NAME_NOT_FOUND.to_string().into())
    }

    pub fn remote_repo_not_found(url: impl AsRef<str>) -> OxenError {
        OxenError::RemoteRepoNotFound(Box::new(StringError::from(url.as_ref())))
    }

    pub fn head_not_found() -> OxenError {
        OxenError::HeadNotFound(StringError::from(HEAD_NOT_FOUND))
    }

    pub fn home_dir_not_found() -> OxenError {
        OxenError::basic_str("Home directory not found")
    }

    pub fn cache_dir_not_found() -> OxenError {
        OxenError::basic_str("Cache directory not found")
    }

    pub fn must_be_on_valid_branch() -> OxenError {
        OxenError::basic_str(
            "Repository is in a detached HEAD state, checkout a valid branch to continue.\n\n  oxen checkout <branch>\n",
        )
    }

    pub fn no_schemas_staged() -> OxenError {
        OxenError::basic_str(
            "No schemas staged\n\nAuto detect schema on file with:\n\n  oxen add path/to/file.csv\n\nOr manually add a schema override with:\n\n  oxen schemas add path/to/file.csv 'name:str, age:i32'\n",
        )
    }

    pub fn no_schemas_committed() -> OxenError {
        OxenError::basic_str(
            "No schemas committed\n\nAuto detect schema on file with:\n\n  oxen add path/to/file.csv\n\nOr manually add a schema override with:\n\n  oxen schemas add path/to/file.csv 'name:str, age:i32'\n\nThen commit the schema with:\n\n  oxen commit -m 'Adding schema for path/to/file.csv'\n",
        )
    }

    pub fn schema_does_not_exist_for_file(path: impl AsRef<Path>) -> OxenError {
        let err = format!("Schema does not exist for file {:?}", path.as_ref());
        OxenError::basic_str(err)
    }

    pub fn schema_does_not_exist(path: impl AsRef<Path>) -> OxenError {
        let err = format!("Schema does not exist {:?}", path.as_ref());
        OxenError::basic_str(err)
    }

    pub fn schema_does_not_have_field(field: impl AsRef<str>) -> OxenError {
        let err = format!("Schema does not have field {:?}", field.as_ref());
        OxenError::basic_str(err)
    }

    pub fn schema_has_changed(old_schema: Schema, current_schema: Schema) -> OxenError {
        let err =
            format!("\nSchema has changed\n\nOld\n{old_schema}\n\nCurrent\n{current_schema}\n");
        OxenError::basic_str(err)
    }

    pub fn remote_branch_not_found(name: impl AsRef<str>) -> OxenError {
        let err = format!("Remote branch '{}' not found", name.as_ref());
        OxenError::BranchNotFound(Box::new(StringError::from(err)))
    }

    pub fn local_branch_not_found(name: impl AsRef<str>) -> OxenError {
        let err = format!("Branch '{}' not found", name.as_ref());
        OxenError::BranchNotFound(Box::new(StringError::from(err)))
    }

    pub fn commit_db_corrupted(commit_id: impl AsRef<str>) -> OxenError {
        let err = format!(
            "Commit db corrupted, could not find commit: {}",
            commit_id.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn commit_id_does_not_exist(commit_id: impl AsRef<str>) -> OxenError {
        let err = format!("Could not find commit: {}", commit_id.as_ref());
        OxenError::basic_str(err)
    }

    pub fn local_parent_link_broken(commit_id: impl AsRef<str>) -> OxenError {
        let err = format!("Broken link to parent commit: {}", commit_id.as_ref());
        OxenError::basic_str(err)
    }

    pub fn entry_does_not_exist(path: impl AsRef<Path>) -> OxenError {
        OxenError::ParsedResourceNotFound(Box::new(path.as_ref().into()))
    }

    pub fn file_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!("File does not exist: {:?} error {:?}", path.as_ref(), error);
        OxenError::basic_str(err)
    }

    pub fn file_create_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!(
            "Could not create file: {:?} error {:?}",
            path.as_ref(),
            error
        );
        OxenError::basic_str(err)
    }

    pub fn dir_create_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!(
            "Could not create directory: {:?} error {:?}",
            path.as_ref(),
            error
        );
        OxenError::basic_str(err)
    }

    pub fn file_open_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!("Could not open file: {:?} error {:?}", path.as_ref(), error,);
        OxenError::basic_str(err)
    }

    pub fn file_read_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!("Could not read file: {:?} error {:?}", path.as_ref(), error,);
        OxenError::basic_str(err)
    }

    pub fn file_metadata_error(path: impl AsRef<Path>, error: std::io::Error) -> OxenError {
        let err = format!(
            "Could not get file metadata: {:?} error {:?}",
            path.as_ref(),
            error
        );
        OxenError::basic_str(err)
    }

    pub fn file_copy_error(
        src: impl AsRef<Path>,
        dst: impl AsRef<Path>,
        err: impl std::fmt::Debug,
    ) -> OxenError {
        let err = format!(
            "File copy error: {err:?}\nCould not copy from `{:?}` to `{:?}`",
            src.as_ref(),
            dst.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn file_rename_error(
        src: impl AsRef<Path>,
        dst: impl AsRef<Path>,
        err: impl std::fmt::Debug,
    ) -> OxenError {
        let err = format!(
            "File rename error: {err:?}\nCould not move from `{:?}` to `{:?}`",
            src.as_ref(),
            dst.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn workspace_add_file_not_in_repo(path: impl AsRef<Path>) -> OxenError {
        let err = format!(
            "File is outside of the repo {:?}\n\nYou must specify a path you would like to add the file at with the -d flag.\n\n  oxen workspace add /path/to/file.png -d my-images/\n",
            path.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn cannot_overwrite_files(paths: &[PathBuf]) -> OxenError {
        let paths_str = paths
            .iter()
            .map(|p| p.to_string_lossy().to_string())
            .collect::<Vec<String>>()
            .join("\n  ");

        OxenError::basic_str(format!(
            "\nError: your local changes to the following files would be overwritten. Please commit the following changes before continuing:\n\n  {paths_str}\n"
        ))
    }

    pub fn entry_does_not_exist_in_commit(
        path: impl AsRef<Path>,
        commit_id: impl AsRef<str>,
    ) -> OxenError {
        let err = format!(
            "Entry {:?} does not exist in commit {}",
            path.as_ref(),
            commit_id.as_ref()
        );
        OxenError::CommitEntryNotFound(err.into())
    }

    pub fn must_supply_valid_api_key() -> OxenError {
        OxenError::basic_str(
            "Must supply valid API key. Create an account at https://oxen.ai and then set the API key with:\n\n  oxen config --auth hub.oxen.ai <API_KEY>\n",
        )
    }

    pub fn file_has_no_parent(path: impl AsRef<Path>) -> OxenError {
        let err = format!("File has no parent: {:?}", path.as_ref());
        OxenError::basic_str(err)
    }

    pub fn file_has_no_name(path: impl AsRef<Path>) -> OxenError {
        let err = format!("File has no file_name: {:?}", path.as_ref());
        OxenError::basic_str(err)
    }

    pub fn could_not_convert_path_to_str(path: impl AsRef<Path>) -> OxenError {
        let err = format!("File has no name: {:?}", path.as_ref());
        OxenError::basic_str(err)
    }

    pub fn local_revision_not_found(name: impl AsRef<str>) -> OxenError {
        let err = format!(
            "Local branch or commit reference `{}` not found",
            name.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn could_not_find_merge_conflict(path: impl AsRef<Path>) -> OxenError {
        let err = format!(
            "Could not find merge conflict for path: {:?}",
            path.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn could_not_decode_value_for_key_error(key: impl AsRef<str>) -> OxenError {
        let err = format!("Could not decode value for key: {:?}", key.as_ref());
        OxenError::basic_str(err)
    }

    pub fn invalid_set_remote_url(url: impl AsRef<str>) -> OxenError {
        let err = format!(
            "\nRemote invalid, must be fully qualified URL, got: {:?}\n\n  oxen config --set-remote origin https://hub.oxen.ai/<namespace>/<reponame>\n",
            url.as_ref()
        );
        OxenError::basic_str(err)
    }

    pub fn invalid_file_type(file_type: impl AsRef<str>) -> OxenError {
        let err = format!("Invalid file type: {:?}", file_type.as_ref());
        OxenError::InvalidFileType(StringError::from(err))
    }

    pub fn column_name_already_exists(column_name: &str) -> OxenError {
        let err = format!("Column name already exists: {column_name:?}");
        OxenError::ColumnNameAlreadyExists(StringError::from(err))
    }

    pub fn column_name_not_found(column_name: &str) -> OxenError {
        let err = format!("Column name not found: {column_name:?}");
        OxenError::ColumnNameNotFound(StringError::from(err))
    }

    pub fn incompatible_schemas(schema: Schema) -> OxenError {
        OxenError::IncompatibleSchemas(Box::new(schema))
    }

    pub fn parse_error(value: impl AsRef<str>) -> OxenError {
        let err = format!("Parse error: {:?}", value.as_ref());
        OxenError::basic_str(err)
    }

    pub fn unknown_subcommand(parent: impl AsRef<str>, name: impl AsRef<str>) -> OxenError {
        OxenError::basic_str(format!(
            "Unknown {} subcommand '{}'",
            parent.as_ref(),
            name.as_ref()
        ))
    }
}

// Manual From impls for types that need transformation
impl From<String> for OxenError {
    fn from(error: String) -> Self {
        OxenError::Basic(StringError::from(error))
    }
}

impl From<StripPrefixError> for OxenError {
    fn from(error: StripPrefixError) -> Self {
        OxenError::basic_str(format!("Error stripping prefix: {error}"))
    }
}

impl From<JoinError> for OxenError {
    fn from(error: JoinError) -> Self {
        OxenError::basic_str(error.to_string())
    }
}

impl From<std::string::FromUtf8Error> for OxenError {
    fn from(error: std::string::FromUtf8Error) -> Self {
        OxenError::basic_str(format!("UTF8 conversion error: {error}"))
    }
}