Skip to content

Commit

Permalink
Merge pull request #21 from freemansoft/features/exceptions
Browse files Browse the repository at this point in the history
Expand on Exception toString()
  • Loading branch information
frederikstonge committed Mar 25, 2024
2 parents 465323b + 16e9906 commit 384de0e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bin/figma2flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:figma2flutter/config/args_parser.dart';
import 'package:figma2flutter/config/options.dart';
import 'package:figma2flutter/exceptions/process_token_exception.dart';
import 'package:figma2flutter/exceptions/resolve_token_exception.dart';
import 'package:figma2flutter/generator.dart';
import 'package:figma2flutter/models/token_theme.dart';
Expand Down Expand Up @@ -111,6 +112,9 @@ Future<void> main(List<String> arguments) async {
} on ResolveTokenException catch (e) {
_print(e.toString(), _red);
rethrow;
} on ProcessTokenException catch (e) {
_print(e.toString(), _red);
rethrow;
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/exceptions/process_token_exception.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class ProcessTokenException {
class ProcessTokenException implements Exception {
final String message;
final Object originalException;

ProcessTokenException(this.message, this.originalException);

@override
String toString() {
return 'ProcessTokenException{message: $message, wrapped: $originalException}';
}
}
2 changes: 1 addition & 1 deletion lib/exceptions/resolve_token_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ResolveTokenException {
class ResolveTokenException implements Exception {
final String message;

ResolveTokenException(this.message);
Expand Down
17 changes: 17 additions & 0 deletions test/exceptions/process_token_exception_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:figma2flutter/exceptions/process_token_exception.dart';
import 'package:figma2flutter/exceptions/resolve_token_exception.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';

void main() {
test('ProcessTokenException message', () {
expect(
ProcessTokenException(
'hello',
ResolveTokenException('some wrapped exception'),
).toString(),
equals(
'ProcessTokenException{message: hello, wrapped: ResolveTokenException{message: some wrapped exception}}'),
);
});
}
12 changes: 12 additions & 0 deletions test/exceptions/resolve_token_exception_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:figma2flutter/exceptions/resolve_token_exception.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';

void main() {
test('ProcessTokenException message', () {
expect(
ResolveTokenException('some wrapped exception').toString(),
equals('ResolveTokenException{message: some wrapped exception}'),
);
});
}

0 comments on commit 384de0e

Please sign in to comment.