Skip to content

Commit 4a8a107

Browse files
committed
Improve error handling
Closes #13
1 parent 3ec9e2a commit 4a8a107

File tree

6 files changed

+55
-19
lines changed

6 files changed

+55
-19
lines changed

Example/Gemfile.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ GEM
1414
json (>= 1.5.1)
1515
atomos (0.1.3)
1616
aws-eventstream (1.1.0)
17-
aws-partitions (1.346.0)
18-
aws-sdk-core (3.104.3)
17+
aws-partitions (1.359.0)
18+
aws-sdk-core (3.105.0)
1919
aws-eventstream (~> 1, >= 1.0.2)
2020
aws-partitions (~> 1, >= 1.239.0)
2121
aws-sigv4 (~> 1.1)
2222
jmespath (~> 1.0)
23-
aws-sdk-kms (1.36.0)
23+
aws-sdk-kms (1.37.0)
2424
aws-sdk-core (~> 3, >= 3.99.0)
2525
aws-sigv4 (~> 1.1)
26-
aws-sdk-s3 (1.75.0)
27-
aws-sdk-core (~> 3, >= 3.104.1)
26+
aws-sdk-s3 (1.79.0)
27+
aws-sdk-core (~> 3, >= 3.104.3)
2828
aws-sdk-kms (~> 1)
2929
aws-sigv4 (~> 1.1)
30-
aws-sigv4 (1.2.1)
30+
aws-sigv4 (1.2.2)
3131
aws-eventstream (~> 1, >= 1.0.2)
3232
babosa (1.0.3)
3333
claide (1.0.3)
@@ -93,7 +93,7 @@ GEM
9393
faraday_middleware (1.0.0)
9494
faraday (~> 1.0)
9595
fastimage (2.2.0)
96-
fastlane (2.153.1)
96+
fastlane (2.156.1)
9797
CFPropertyList (>= 2.3, < 4.0.0)
9898
addressable (>= 2.3, < 3.0.0)
9999
aws-sdk-s3 (~> 1.0)
@@ -147,14 +147,14 @@ GEM
147147
google-cloud-env (1.3.3)
148148
faraday (>= 0.17.3, < 2.0)
149149
google-cloud-errors (1.0.1)
150-
google-cloud-storage (1.26.2)
150+
google-cloud-storage (1.27.0)
151151
addressable (~> 2.5)
152152
digest-crc (~> 0.4)
153153
google-api-client (~> 0.33)
154154
google-cloud-core (~> 1.2)
155155
googleauth (~> 0.9)
156156
mini_mime (~> 1.0)
157-
googleauth (0.13.0)
157+
googleauth (0.13.1)
158158
faraday (>= 0.17.3, < 2.0)
159159
jwt (>= 1.4, < 3.0)
160160
memoist (~> 0.16)
@@ -169,7 +169,7 @@ GEM
169169
concurrent-ruby (~> 1.0)
170170
jmespath (1.4.0)
171171
json (2.3.1)
172-
jwt (2.2.1)
172+
jwt (2.2.2)
173173
memoist (0.16.2)
174174
mini_magick (4.10.1)
175175
mini_mime (1.0.2)
@@ -181,7 +181,7 @@ GEM
181181
nap (1.1.0)
182182
naturally (2.2.0)
183183
netrc (0.11.0)
184-
os (1.1.0)
184+
os (1.1.1)
185185
plist (3.5.0)
186186
public_suffix (4.0.5)
187187
rake (13.0.1)
@@ -221,7 +221,7 @@ GEM
221221
unf_ext (0.0.7.7)
222222
unicode-display_width (1.7.0)
223223
word_wrap (1.0.0)
224-
xcodeproj (1.17.1)
224+
xcodeproj (1.18.0)
225225
CFPropertyList (>= 2.3.3, < 4.0)
226226
atomos (~> 0.1.3)
227227
claide (>= 1.0.2, < 2.0)

Sources/FigmaAPI/Model/FigmaClientError.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,20 @@ struct FigmaClientError: Decodable, LocalizedError {
44
let status: Int
55
let err: String
66

7-
var errorDescription: String? { "Figma API: \(err)" }
7+
var errorDescription: String? {
8+
switch err {
9+
case "Not found":
10+
return "Figma file not found. Check lightFileId and darkFileId (if you project supports dark mode) in the yaml config file."
11+
default:
12+
return "Figma API: \(err)"
13+
}
14+
}
15+
}
16+
17+
extension FigmaClientError: Equatable {
18+
19+
static let notFound = FigmaClientError(
20+
status: 404,
21+
err: "Not found"
22+
)
823
}

Sources/FigmaExport/Loaders/ColorsLoader.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ final class ColorsLoader {
2222

2323
private func loadColors(fileId: String) throws -> [Color] {
2424
let styles = try loadStyles(fileId: fileId)
25+
26+
guard !styles.isEmpty else {
27+
throw FigmaExportError.stylesNotFound
28+
}
29+
2530
let nodes = try loadNodes(fileId: fileId, nodeIds: styles.map { $0.nodeId } )
2631
return nodesAndStylesToColors(nodes: nodes, styles: styles)
2732
}

Sources/FigmaExport/Loaders/ImagesLoader.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ final class ImagesLoader {
9191

9292
private func _loadImages(fileId: String, frameName: FrameName, params: FormatParams, filter: String? = nil) throws -> [Image] {
9393
let imagesDict = try fetchImageComponents(fileId: fileId, frameName: frameName, filter: filter)
94+
95+
guard !imagesDict.isEmpty else {
96+
throw FigmaExportError.componentsNotFound
97+
}
98+
9499
let imagesIds: [NodeId] = imagesDict.keys.map { $0 }
95100
let imageIdToImagePath = try loadImages(fileId: fileId, nodeIds: imagesIds, params: params)
96101

@@ -106,6 +111,11 @@ final class ImagesLoader {
106111

107112
private func _loadPNGImages(fileId: String, frameName: FrameName, filter: String? = nil) throws -> [ImagePack] {
108113
let imagesDict = try fetchImageComponents(fileId: fileId, frameName: frameName, filter: filter)
114+
115+
guard !imagesDict.isEmpty else {
116+
throw FigmaExportError.componentsNotFound
117+
}
118+
109119
let imagesIds: [NodeId] = imagesDict.keys.map { $0 }
110120

111121
let imageIdToImagePath1 = try loadImages(fileId: fileId, nodeIds: imagesIds, params: PNGParams(scale: 1))

Sources/FigmaExport/Processor/AssetsValidatorError.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ enum AssetsValidatorError: LocalizedError {
1111
var errorDescription: String? {
1212
switch self {
1313
case .badName(let name):
14-
return "Неправильное название «\(name)»"
14+
return "Bad asset name «\(name)»"
1515
case .countMismatch(let light, let dark):
16-
return "Количество ассетов не совпадает. В светлой теме их \(light), а в темной теме \(dark)."
16+
return "The number of assets doesn’t match. Light theme contains \(light), and dark \(dark)."
1717
case .lightAssetsNotFoundInDarkPalette(let lights):
18-
return "В темной теме не найдены ассеты: \(lights.joined(separator: ", ")), которые есть в светлой теме."
18+
return "Dark theme doesn’t contains following assets: \(lights.joined(separator: ", ")), which exists in light theme. Add these assets to dark theme and publish to the Team Library."
1919
case .darkAssetsNotFoundInLightPalette(let darks):
20-
return "В светлой теме не найдены ассеты: \(darks.joined(separator: ", ")), которые есть в темной теме."
20+
return "Light theme doesn’t contains following assets: \(darks.joined(separator: ", ")), which exists in dark theme. Add these assets to light theme and publish to the Team Library."
2121
case .foundDuplicate(let assetName):
22-
return "Ассет \(assetName) встречается несколько раз."
22+
return "Found duplicates of asset with name \(assetName). Remove duplicates."
2323
case .descriptionMismatch(let assetName, let light, let dark):
24-
return "Ассет \(assetName) имеет разный description. В тёмной теме «\(dark)», а в светлой «\(light)»"
24+
return "Asset with name \(assetName) have different description. In dark theme «\(dark)», in light theme «\(light)»"
2525
}
2626
}
2727
}

Sources/FigmaExport/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import Foundation
33

44
enum FigmaExportError: LocalizedError {
55

6+
case stylesNotFound
7+
case componentsNotFound
68
case accessTokenNotFound
79
case colorsAssetsFolderNotSpecified
810

911
var errorDescription: String? {
1012
switch self {
13+
case .stylesNotFound:
14+
return "Color styles not found in the Figma file. Have you published Styles to the Library?"
15+
case .componentsNotFound:
16+
return "Components not found in the Figma file. Have you published Components to the Library?"
1117
case .accessTokenNotFound:
1218
return "Environment varibale FIGMA_PERSONAL_TOKEN not specified."
1319
case .colorsAssetsFolderNotSpecified:

0 commit comments

Comments
 (0)