1use crate::error::archive::GetArchivePathError;
2use crate::error::fs::{
3 CreateDirAllError, EnsureDirExistsError, ReadDirError, ReadFileError, ReadPermissionsError,
4 RemoveDirectoryAndContentsError, SetPermissionsError, UnpackingArchiveError, WriteFileError,
5};
6use crate::error::get_current_exe::GetCurrentExeError;
7use crate::error::get_user_home::GetUserHomeError;
8use std::path::PathBuf;
9use thiserror::Error;
10
11#[derive(Error, Debug)]
12pub enum DeleteCacheError {
13 #[error(transparent)]
14 GetBinCache(#[from] EnsureCacheVersionsDirError),
15
16 #[error(transparent)]
17 RemoveDirectoryAndContents(#[from] RemoveDirectoryAndContentsError),
18}
19
20#[derive(Error, Debug)]
21pub enum GetBinaryCommandPathError {
22 #[error(transparent)]
23 Install(#[from] InstallCacheError),
24
25 #[error(transparent)]
26 GetBinCacheRoot(#[from] EnsureCacheVersionsDirError),
27}
28
29#[derive(Error, Debug)]
30pub enum EnsureCacheVersionsDirError {
31 #[error(transparent)]
32 EnsureDirExists(#[from] EnsureDirExistsError),
33
34 #[error(transparent)]
35 GetCacheRoot(#[from] GetCacheRootError),
36}
37
38#[derive(Error, Debug)]
39pub enum GetVersionFromCachePathError {
40 #[error("no filename in cache path '{0}'")]
41 NoCachePathFilename(PathBuf),
42
43 #[error("filename in cache path '{0}' is not valid UTF-8")]
44 CachePathFilenameNotUtf8(PathBuf),
45
46 #[error("cannot parse version from cache path filename")]
47 ParseVersion(#[from] semver::Error),
48}
49
50#[derive(Error, Debug)]
51pub enum GetCacheRootError {
52 #[error(transparent)]
53 GetUserHomeError(#[from] GetUserHomeError),
54
55 #[error("failed to find cache directory at '{0}'.")]
56 FindCacheDirectoryFailed(std::path::PathBuf),
57}
58
59#[derive(Error, Debug)]
60pub enum InstallCacheError {
61 #[error(transparent)]
62 CreateDirAll(#[from] CreateDirAllError),
63
64 #[error(transparent)]
65 GetArchivePath(#[from] GetArchivePathError),
66
67 #[error(transparent)]
68 GetBinCache(#[from] EnsureCacheVersionsDirError),
69
70 #[error(transparent)]
71 GetCurrentExeError(#[from] GetCurrentExeError),
72
73 #[error("invalid cache for version '{0}'.")]
74 InvalidCacheForDfxVersion(String),
75
76 #[error("failed to parse '{0}' as Semantic Version")]
77 MalformedSemverString(String, #[source] semver::Error),
78
79 #[error("failed to iterate through binary cache")]
80 ReadBinaryCacheEntriesFailed(#[source] std::io::Error),
81
82 #[error("failed to read binary cache entry")]
83 ReadBinaryCacheEntryFailed(#[source] std::io::Error),
84
85 #[error("failed to read binary cache")]
86 ReadBinaryCacheStoreFailed(#[source] std::io::Error),
87
88 #[error(transparent)]
89 ReadFile(#[from] ReadFileError),
90
91 #[error(transparent)]
92 ReadPermissions(#[from] ReadPermissionsError),
93
94 #[error(transparent)]
95 RemoveDirectoryAndContents(#[from] RemoveDirectoryAndContentsError),
96
97 #[error(transparent)]
98 SetPermissions(#[from] SetPermissionsError),
99
100 #[error(transparent)]
101 UnpackingArchive(#[from] UnpackingArchiveError),
102
103 #[error(transparent)]
104 WriteFile(#[from] WriteFileError),
105}
106
107#[derive(Error, Debug)]
108pub enum IsCacheInstalledError {
109 #[error(transparent)]
110 GetBinCache(#[from] EnsureCacheVersionsDirError),
111}
112
113#[derive(Error, Debug)]
114pub enum ListCacheVersionsError {
115 #[error(transparent)]
116 ReadDir(#[from] ReadDirError),
117
118 #[error(transparent)]
119 GetBinCacheRoot(#[from] EnsureCacheVersionsDirError),
120
121 #[error("failed to parse '{0}' as Semantic Version")]
122 MalformedSemverString(String, #[source] semver::Error),
123
124 #[error("failed to read entry in cache directory")]
125 ReadCacheEntryFailed(#[source] std::io::Error),
126}