Skip to content

Commit 56af8af

Browse files
committed
Fixed script exit code on error.
1 parent c53cddc commit 56af8af

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@
4949

5050
## 3.0.0-nullsafety.0
5151

52-
- Updated the tool to null safety
52+
- Updated the tool to null safety
53+
54+
## 3.0.0
55+
56+
- Fixed script exit code on error.
57+
58+
- Updated library dependencies versions.
59+
60+
- Updated dart version 2.13.4

bin/dbstyleguidechecker.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import 'dart:io';
3636

3737
import 'package:dbstyleguidechecker/dbstyleguidechecker.dart';
3838
import 'package:args/args.dart';
39+
import 'package:io/io.dart';
3940

4041
/// Run the script with the provided [arguments].
4142
Future<void> main(List<String> arguments) async {
@@ -62,7 +63,7 @@ Future<void> main(List<String> arguments) async {
6263
} on UnrecoverableException catch (exception) {
6364
printHelpMessage(exception.reason);
6465
exitCode = exception.exitCode;
65-
return;
66+
exit(exitCode);
6667
}
6768

6869
Directory.current = scriptArgument.projectDir.path;
@@ -77,19 +78,24 @@ Future<void> main(List<String> arguments) async {
7778
} on UnrecoverableException catch (exception) {
7879
printHelpMessage(exception.reason);
7980
exitCode = exception.exitCode;
80-
return;
81+
exit(exitCode);
8182
}
8283

8384
await runZonedGuarded<Future<void>>(
8485
checker.check,
8586
(Object error, StackTrace stackTrace) {
86-
printHelpMessage(error.toString());
87+
final String errorMessage;
8788

8889
if (error is UnrecoverableException) {
90+
errorMessage = error.reason;
8991
exitCode = error.exitCode;
9092
} else {
91-
exitCode = exitUnexpectedError;
93+
errorMessage = error.toString();
94+
exitCode = ExitCode.software.code;
9295
}
96+
97+
printHelpMessage(errorMessage);
98+
exit(exitCode);
9399
},
94100
);
95101
}

lib/src/reporters/github/github_api_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class GithubApiService {
135135
final Map<String, dynamic> reviewStatus = <String, dynamic>{
136136
'event': 'REQUEST_CHANGES',
137137
'body': 'Your pull request seems to contains some '
138-
'code style guide violation, please verify them'
138+
'code style violation, please verify them'
139139
};
140140

141141
if (commitId != null) {

lib/src/reporters/github/github_pull_request_style_guide_check_reporter.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import 'package:dbstyleguidechecker/src/reporters/github/github_api_service.dart
3636
import 'package:dbstyleguidechecker/src/reporters/github/github_file_diff.dart';
3737
import 'package:dbstyleguidechecker/src/code_style_violation.dart';
3838
import 'package:dbstyleguidechecker/src/utils/file_utils.dart';
39+
import 'package:io/io.dart';
3940

4041
/// Github pull request style guide check reporter.
4142
class GithubPullRequestStyleGuideCheckReporter
@@ -95,8 +96,17 @@ class GithubPullRequestStyleGuideCheckReporter
9596
);
9697

9798
if (latestCommitId == null) {
99+
throw UnrecoverableException(
100+
'Could not get the last commit id',
101+
ExitCode.tempFail.code,
102+
);
98103
} else if (pullRequestNeedFixes) {
99104
await _service.requestChanges(latestCommitId, pullRequestId);
105+
throw UnrecoverableException(
106+
'Your pull request seems to contains some '
107+
'code style violation, please verify them',
108+
ExitCode.tempFail.code,
109+
);
100110
} else {
101111
await _service.onCodeStyleViolationNotFound(
102112
latestCommitId,

pubspec.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
name: dbstyleguidechecker
22
description: A tool that help you verify a project agains code style guide and automatize pull request review.
3-
version: 3.0.0-nullsafety.0
3+
version: 3.0.0
44
homepage: https://github.com/bitsydarel/dbstyleguidechecker
55
repository: https://github.com/bitsydarel/dbstyleguidechecker
66
issue_tracker: https://github.com/bitsydarel/dbstyleguidechecker/issues
77

88
environment:
9-
sdk: '>=2.12.0 <3.0.0'
9+
sdk: '>=2.13.4 <3.0.0'
1010

1111
dependencies:
12-
args: ^2.0.0
13-
http: ^0.13.0
14-
io: ^1.0.0
15-
meta: ^1.3.0
12+
args: ^2.2.0
13+
http: ^0.13.3
14+
io: ^1.0.3
15+
meta: ^1.7.0
1616
path: ^1.8.0
1717

1818
dev_dependencies:
19-
flutter_code_style: ^2.0.2
20-
test: ^1.15.7
19+
flutter_code_style: ^2.1.0
20+
test: ^1.17.10
2121

2222
executables:
2323
dbstyleguidechecker:

0 commit comments

Comments
 (0)