@@ -16,7 +16,7 @@ import * as awarenessProtocol from 'y-protocols/awareness.js';
1616import * as encoding from 'lib0/encoding.js' ;
1717import * as decoding from 'lib0/decoding.js' ;
1818import debounce from 'lodash/debounce.js' ;
19- import { aem2doc , doc2aem } from './collab.js' ;
19+ import { aem2doc , doc2aem , EMPTY_DOC } from './collab.js' ;
2020
2121const wsReadyStateConnecting = 0 ;
2222const wsReadyStateOpen = 1 ;
@@ -27,7 +27,6 @@ const gcEnabled = false;
2727// The local cache of ydocs
2828const docs = new Map ( ) ;
2929
30- const EMPTY_DOC = '<main></main>' ;
3130const messageSync = 0 ;
3231const messageAwareness = 1 ;
3332const MAX_STORAGE_KEYS = 128 ;
@@ -153,14 +152,19 @@ export const storeState = async (docName, state, storage, chunkSize = MAX_STORAG
153152} ;
154153
155154export const showError = ( ydoc , err ) => {
156- const em = ydoc . getMap ( 'error' ) ;
155+ try {
156+ const em = ydoc . getMap ( 'error' ) ;
157157
158- // Perform the change in a transaction to avoid seeing a partial error
159- ydoc . transact ( ( ) => {
160- em . set ( 'timestamp' , Date . now ( ) ) ;
161- em . set ( 'message' , err . message ) ;
162- em . set ( 'stack' , err . stack ) ;
163- } ) ;
158+ // Perform the change in a transaction to avoid seeing a partial error
159+ ydoc . transact ( ( ) => {
160+ em . set ( 'timestamp' , Date . now ( ) ) ;
161+ em . set ( 'message' , err . message ) ;
162+ em . set ( 'stack' , err . stack ) ;
163+ } ) ;
164+ } catch ( e ) {
165+ // eslint-disable-next-line no-console
166+ console . error ( 'Error showing error' , e , err ) ;
167+ }
164168} ;
165169
166170export const persistence = {
@@ -330,6 +334,8 @@ export const persistence = {
330334 // The doc was not restored from worker persistence, so read it from da-admin,
331335 // but do this async to give the ydoc some time to get synced up first. Without
332336 // this timeout, the ydoc can get confused which may result in duplicated content.
337+ // eslint-disable-next-line no-console
338+ console . log ( 'Could not be restored, trying to restore from da-admin' , docName ) ;
333339 setTimeout ( ( ) => {
334340 if ( ydoc === docs . get ( docName ) ) {
335341 const rootType = ydoc . getXmlFragment ( 'prosemirror' ) ;
@@ -344,7 +350,7 @@ export const persistence = {
344350 console . log ( 'Restored from da-admin' , docName ) ;
345351 } catch ( error ) {
346352 // eslint-disable-next-line no-console
347- console . error ( 'Problem restoring state from da-admin' , error ) ;
353+ console . error ( 'Problem restoring state from da-admin' , error , current ) ;
348354 showError ( ydoc , error ) ;
349355 }
350356 } ) ;
0 commit comments