Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60c48ed

Browse files
committed
improve build error handling
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent0337a3c commit60c48ed

File tree

3 files changed

+72
-17
lines changed

3 files changed

+72
-17
lines changed

‎src/build.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,72 @@ const parseArgs = (args: string[]): BuildArgs => {
4646
};
4747

4848
asyncfunctionbuild(args:string[]){
49-
constoptions=parseArgs(args);
49+
letoptions:BuildArgs;
50+
try{
51+
options=parseArgs(args);
52+
}catch(e){
53+
console.error("Error parsing build logs");
54+
console.error(e.message);
55+
return;
56+
}
5057

5158
// path to run build from
5259
constlocalPath=path.join(process.cwd(),options.dir);
5360

5461
// load files
55-
const[_markdown,_yaml]=awaitPromise.all([
56-
read(path.join(localPath,options.markdown),"utf8"),
57-
read(path.join(localPath,options.yaml),"utf8"),
58-
]);
62+
let_markdown:string;
63+
let_yaml:string;
64+
try{
65+
[_markdown,_yaml]=awaitPromise.all([
66+
read(path.join(localPath,options.markdown),"utf8"),
67+
read(path.join(localPath,options.yaml),"utf8"),
68+
]);
69+
}catch(e){
70+
console.error("Error reading file:");
71+
console.error(e.message);
72+
return;
73+
}
5974

60-
constconfig=yamlParser.load(_yaml);
75+
letconfig;
76+
try{
77+
config=yamlParser.load(_yaml);
78+
}catch(e){
79+
console.error("Error parsing yaml");
80+
console.error(e.message);
81+
}
6182

62-
constcommits:CommitLogObject=awaitgetCommits(config.config.repo.branch);
83+
letcommits:CommitLogObject;
84+
try{
85+
commits=awaitgetCommits({
86+
localDir:localPath,
87+
codeBranch:config.config.repo.branch,
88+
});
89+
}catch(e){
90+
console.error("Error loading commits:");
91+
console.error(e.message);
92+
return;
93+
}
6394

6495
// Otherwise, continue with the other options
65-
consttutorial:T.Tutorial=awaitparse({
66-
text:_markdown,
67-
config,
68-
commits,
69-
});
96+
lettutorial:T.Tutorial;
97+
try{
98+
tutorial=awaitparse({
99+
text:_markdown,
100+
config,
101+
commits,
102+
});
103+
}catch(e){
104+
console.error("Error parsing tutorial:");
105+
console.error(e.message);
106+
return;
107+
}
70108

71109
if(tutorial){
72-
if(options.output){
110+
try{
73111
awaitwrite(options.output,JSON.stringify(tutorial),"utf8");
74-
}else{
75-
console.log(JSON.stringify(tutorial,null,2));
112+
}catch(e){
113+
console.error("Error writing tutorial json:");
114+
console.error(e.message);
76115
}
77116
}
78117
}

‎src/utils/commits.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,26 @@ export async function getCommits({
3737
consttempGit=gitP(tmpDir);
3838
awaittempGit.clone(localDir,tmpDir);
3939

40+
constbranches=awaitgit.branch();
41+
42+
if(!branches.all.length){
43+
thrownewError("No branches found");
44+
}elseif(!branches.all.includes(codeBranch)){
45+
thrownewError(`Code branch "${codeBranch}" not found`);
46+
}
47+
48+
console.log("branches",branches);
49+
4050
// Checkout the code branches
4151
awaitgit.checkout(codeBranch);
4252

53+
console.log("checked out");
54+
4355
// Load all logs
4456
constlogs=awaitgit.log();
4557

58+
console.log("logs",logs);
59+
4660
// Filter relevant logs
4761
constcommits:CommitLogObject={};
4862

@@ -63,6 +77,8 @@ export async function getCommits({
6377
}
6478
}
6579
}
80+
81+
console.log("remove");
6682
// cleanup the tmp directory
6783
awaitrmdir(tmpDir,{recursive:true});
6884
returncommits;

‎tests/parse.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe("parse", () => {
55
it("should parse summary",()=>{
66
constmd=`# Insert Tutorial's Title here
77
8-
Short description to be shown as a tutorial's subtitle.
8+
Short description to be shown as a tutorial's subtitle.
99
10-
`;
10+
`;
1111

1212
constconfig={version:"0.1.0"};
1313
constresult=parse({

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp