@@ -40,16 +40,27 @@ export async function addNote55(
4040 } ) ;
4141
4242 if ( result . ok ) {
43- // create cards
44- await createCards ( courseID , dataShapeId , result . id , tags , elo ) ;
43+ try {
44+ // create cards
45+ await createCards ( courseID , dataShapeId , result . id , tags , elo ) ;
46+ } catch ( error ) {
47+ console . error (
48+ `[addNote55] Failed to create cards for note ${ result . id } : ${
49+ error instanceof Error ? error . message : String ( error )
50+ } `
51+ ) ;
52+ // Add info to result to indicate card creation failed
53+ ( result as any ) . cardCreationFailed = true ;
54+ ( result as any ) . cardCreationError = error instanceof Error ? error . message : String ( error ) ;
55+ }
4556 } else {
46- console . log ( ` Error adding note: ${ result } `) ;
57+ console . error ( `[addNote55] Error adding note. Result : ${ JSON . stringify ( result ) } `) ;
4758 }
4859
4960 return result ;
5061}
5162
52- export async function createCards (
63+ async function createCards (
5364 courseID : string ,
5465 datashapeID : PouchDB . Core . DocumentId ,
5566 noteID : PouchDB . Core . DocumentId ,
@@ -66,8 +77,16 @@ export async function createCards(
6677 }
6778 }
6879
80+ if ( questionViewTypes . length === 0 ) {
81+ const errorMsg = `No questionViewTypes found for datashapeID: ${ datashapeID } in course config. Cards cannot be created.` ;
82+ console . error ( errorMsg ) ;
83+ throw new Error ( errorMsg ) ;
84+ }
85+
86+ let createdCards = 0 ;
6987 for ( const questionView of questionViewTypes ) {
70- createCard ( questionView , courseID , dsDescriptor , noteID , tags , elo ) ;
88+ await createCard ( questionView , courseID , dsDescriptor , noteID , tags , elo ) ;
89+ createdCards ++ ;
7190 }
7291}
7392
@@ -86,7 +105,7 @@ async function createCard(
86105 for ( const rQ of cfg . questionTypes ) {
87106 if ( rQ . name === questionViewName ) {
88107 for ( const view of rQ . viewList ) {
89- addCard (
108+ await addCard (
90109 courseID ,
91110 dsDescriptor . course ,
92111 [ noteID ] ,
0 commit comments