mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(core): Enforce config file permissions on startup (#11328)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <netroy@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { ensureError } from './errors';
|
||||
|
||||
export type ResultOk<T> = { ok: true; result: T };
|
||||
export type ResultError<E> = { ok: false; error: E };
|
||||
export type Result<T, E> = ResultOk<T> | ResultError<E>;
|
||||
@@ -11,3 +13,18 @@ export const createResultError = <E = unknown>(error: E): ResultError<E> => ({
|
||||
ok: false,
|
||||
error,
|
||||
});
|
||||
|
||||
/**
|
||||
* Executes the given function and converts it to a Result object.
|
||||
*
|
||||
* @example
|
||||
* const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));
|
||||
*/
|
||||
export const toResult = <T, E extends Error = Error>(fn: () => T): Result<T, E> => {
|
||||
try {
|
||||
return createResultOk<T>(fn());
|
||||
} catch (e) {
|
||||
const error = ensureError(e);
|
||||
return createResultError<E>(error as E);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user