Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
137 lines
4.1 KiB
JavaScript
137 lines
4.1 KiB
JavaScript
function isErrorInstance(obj) {
|
|
return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
|
|
}
|
|
|
|
function isRegExp(obj) {
|
|
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
}
|
|
|
|
/**
|
|
* ### .compatibleInstance(thrown, errorLike)
|
|
*
|
|
* Checks if two instances are compatible (strict equal).
|
|
* Returns false if errorLike is not an instance of Error, because instances
|
|
* can only be compatible if they're both error instances.
|
|
*
|
|
* @name compatibleInstance
|
|
* @param {Error} thrown error
|
|
* @param {Error|ErrorConstructor} errorLike object to compare against
|
|
* @namespace Utils
|
|
* @api public
|
|
*/
|
|
|
|
function compatibleInstance(thrown, errorLike) {
|
|
return isErrorInstance(errorLike) && thrown === errorLike;
|
|
}
|
|
|
|
/**
|
|
* ### .compatibleConstructor(thrown, errorLike)
|
|
*
|
|
* Checks if two constructors are compatible.
|
|
* This function can receive either an error constructor or
|
|
* an error instance as the `errorLike` argument.
|
|
* Constructors are compatible if they're the same or if one is
|
|
* an instance of another.
|
|
*
|
|
* @name compatibleConstructor
|
|
* @param {Error} thrown error
|
|
* @param {Error|ErrorConstructor} errorLike object to compare against
|
|
* @namespace Utils
|
|
* @api public
|
|
*/
|
|
|
|
function compatibleConstructor(thrown, errorLike) {
|
|
if (isErrorInstance(errorLike)) {
|
|
// If `errorLike` is an instance of any error we compare their constructors
|
|
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
|
|
} else if ((typeof errorLike === 'object' || typeof errorLike === 'function') && errorLike.prototype) {
|
|
// If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
|
|
return thrown.constructor === errorLike || thrown instanceof errorLike;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* ### .compatibleMessage(thrown, errMatcher)
|
|
*
|
|
* Checks if an error's message is compatible with a matcher (String or RegExp).
|
|
* If the message contains the String or passes the RegExp test,
|
|
* it is considered compatible.
|
|
*
|
|
* @name compatibleMessage
|
|
* @param {Error} thrown error
|
|
* @param {String|RegExp} errMatcher to look for into the message
|
|
* @namespace Utils
|
|
* @api public
|
|
*/
|
|
|
|
function compatibleMessage(thrown, errMatcher) {
|
|
const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
|
|
if (comparisonString === undefined) {
|
|
return false;
|
|
}
|
|
if (isRegExp(errMatcher)) {
|
|
return errMatcher.test(comparisonString);
|
|
} else if (typeof errMatcher === 'string') {
|
|
return comparisonString.indexOf(errMatcher) !== -1;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* ### .getConstructorName(errorLike)
|
|
*
|
|
* Gets the constructor name for an Error instance or constructor itself.
|
|
*
|
|
* @name getConstructorName
|
|
* @param {Error|ErrorConstructor} errorLike
|
|
* @namespace Utils
|
|
* @api public
|
|
*/
|
|
|
|
function getConstructorName(errorLike) {
|
|
let constructorName = errorLike;
|
|
if (isErrorInstance(errorLike)) {
|
|
constructorName = errorLike.constructor.name;
|
|
} else if (typeof errorLike === 'function') {
|
|
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
|
// If we've got a common function we get its name, otherwise we may need to create a new instance
|
|
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
|
|
constructorName = errorLike.name;
|
|
if (constructorName === '') {
|
|
const newConstructorName = (new errorLike().name);
|
|
constructorName = newConstructorName || constructorName;
|
|
}
|
|
}
|
|
|
|
return constructorName;
|
|
}
|
|
|
|
/**
|
|
* ### .getMessage(errorLike)
|
|
*
|
|
* Gets the error message from an error.
|
|
* If `err` is a String itself, we return it.
|
|
* If the error has no message, we return an empty string.
|
|
*
|
|
* @name getMessage
|
|
* @param {Error|String} errorLike
|
|
* @namespace Utils
|
|
* @api public
|
|
*/
|
|
|
|
function getMessage(errorLike) {
|
|
let msg = '';
|
|
if (errorLike && errorLike.message) {
|
|
msg = errorLike.message;
|
|
} else if (typeof errorLike === 'string') {
|
|
msg = errorLike;
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
export { compatibleInstance, compatibleConstructor, compatibleMessage, getMessage, getConstructorName };
|