(ogErr, appOrParcel, newStatus)
| 56 | } |
| 57 | |
| 58 | export function transformErr(ogErr, appOrParcel, newStatus) { |
| 59 | const errPrefix = `${objectType(appOrParcel)} '${toName( |
| 60 | appOrParcel |
| 61 | )}' died in status ${appOrParcel.status}: `; |
| 62 | |
| 63 | let result; |
| 64 | |
| 65 | if (ogErr instanceof Error) { |
| 66 | try { |
| 67 | ogErr.message = errPrefix + ogErr.message; |
| 68 | } catch (err) { |
| 69 | /* Some errors have read-only message properties, in which case there is nothing |
| 70 | * that we can do. |
| 71 | */ |
| 72 | } |
| 73 | result = ogErr; |
| 74 | } else { |
| 75 | console.warn( |
| 76 | formatErrorMessage( |
| 77 | 30, |
| 78 | __DEV__ && |
| 79 | `While ${appOrParcel.status}, '${toName( |
| 80 | appOrParcel |
| 81 | )}' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate.`, |
| 82 | appOrParcel.status, |
| 83 | toName(appOrParcel) |
| 84 | ) |
| 85 | ); |
| 86 | try { |
| 87 | result = Error(errPrefix + JSON.stringify(ogErr)); |
| 88 | } catch (err) { |
| 89 | // If it's not an Error and you can't stringify it, then what else can you even do to it? |
| 90 | result = ogErr; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | result.appOrParcelName = toName(appOrParcel); |
| 95 | |
| 96 | // We set the status after transforming the error so that the error message |
| 97 | // references the state the application was in before the status change. |
| 98 | appOrParcel.status = newStatus; |
| 99 | |
| 100 | return result; |
| 101 | } |
no test coverage detected
searching dependent graphs…