mirror of
https://github.com/xodio/xod.git
synced 2026-02-20 02:01:20 +01:00
feat(xod-fs, xod-client-electron): show error if loaded project or libraries has invalid patch paths
This commit is contained in:
@@ -3,6 +3,7 @@ import { messages as xpMessages } from 'xod-project';
|
||||
import { messages as xdMessages } from 'xod-deploy';
|
||||
import { messages as xdbMessages } from 'xod-deploy-bin';
|
||||
import { messages as xardMessages } from 'xod-arduino';
|
||||
import { messages as xfMessages } from 'xod-fs';
|
||||
|
||||
import uploadMessages from '../upload/messages';
|
||||
|
||||
@@ -11,6 +12,7 @@ export const formatErrorMessage = composeErrorFormatters([
|
||||
xdMessages,
|
||||
xdbMessages,
|
||||
xardMessages,
|
||||
xfMessages,
|
||||
uploadMessages,
|
||||
]);
|
||||
|
||||
|
||||
@@ -9,3 +9,6 @@ export const CANT_ENUMERATE_PROJECTS = 'CANT_ENUMERATE_PROJECTS';
|
||||
export const CANT_SAVE_PROJECT = 'CANT_SAVE_PROJECT';
|
||||
export const CANT_SAVE_LIBRARY = 'CANT_SAVE_LIBRARY';
|
||||
export const INVALID_FILE_CONTENTS = 'INVALID_FILE_CONTENTS';
|
||||
|
||||
export const PROJECT_LOADED_WITH_INVALID_PATCH_PATHS =
|
||||
'PROJECT_LOADED_WITH_INVALID_PATCH_PATHS';
|
||||
|
||||
@@ -31,6 +31,7 @@ export {
|
||||
isWorkspaceDir,
|
||||
getPathToXodProject,
|
||||
} from './find';
|
||||
export { default as messages } from './messages';
|
||||
|
||||
export * from './constants';
|
||||
|
||||
|
||||
@@ -28,6 +28,36 @@ import {
|
||||
addMissingOptionsToPatchFileContents,
|
||||
addMissingOptionsToProjectFileContents,
|
||||
} from './convertTypes';
|
||||
|
||||
// =============================================================================
|
||||
//
|
||||
// Validate loaded project
|
||||
//
|
||||
// xod-fs returns a `LoadResult` type, which contains a validated
|
||||
// and probably patched with some fixes Project and a list of warnings
|
||||
//
|
||||
// =============================================================================
|
||||
|
||||
// :: Project -> Promise Project Error
|
||||
const validateLoadedProject = project =>
|
||||
R.compose(
|
||||
R.ifElse(
|
||||
corrupted => corrupted.length,
|
||||
patchPaths =>
|
||||
Promise.reject(
|
||||
XF.createError(ERROR_CODES.PROJECT_LOADED_WITH_INVALID_PATCH_PATHS, {
|
||||
patchPaths,
|
||||
})
|
||||
),
|
||||
() => Promise.resolve(project)
|
||||
),
|
||||
R.filter(
|
||||
R.both(R.complement(XP.isPathLocal), R.complement(XP.isPathLibrary))
|
||||
),
|
||||
R.map(XP.getPatchPath),
|
||||
XP.listGenuinePatches
|
||||
)(project);
|
||||
|
||||
// =============================================================================
|
||||
//
|
||||
// Reading of files
|
||||
@@ -220,9 +250,10 @@ export const loadProjectFromXodball = R.curry((workspaceDirs, xodballPath) =>
|
||||
* If other extension is passed into this function it will return
|
||||
* rejected Promise with Error. Otherwise, Promise Project.
|
||||
*/
|
||||
// :: [Path] -> Path -> Promise Project Error
|
||||
// :: [Path] -> Path -> Promise Promise Error
|
||||
export const loadProject = R.uncurryN(2, workspaceDirs =>
|
||||
R.composeP(
|
||||
validateLoadedProject,
|
||||
XP.migrateBoundValuesToBoundLiterals,
|
||||
R.ifElse(
|
||||
isExtname('.xodball'),
|
||||
|
||||
21
packages/xod-fs/src/messages.js
Normal file
21
packages/xod-fs/src/messages.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as R from 'ramda';
|
||||
import { PROJECT_LOADED_WITH_INVALID_PATCH_PATHS } from './errorCodes';
|
||||
|
||||
const formatPatchPaths = R.compose(
|
||||
R.join(', '),
|
||||
R.when(
|
||||
patchPaths => patchPaths.length > 3,
|
||||
R.compose(R.append('…'), R.take(3))
|
||||
)
|
||||
);
|
||||
|
||||
export default {
|
||||
[PROJECT_LOADED_WITH_INVALID_PATCH_PATHS]: ({ patchPaths }) => ({
|
||||
title: 'Cannot load some patches',
|
||||
note: `Some patches have an invalid patch paths: ${formatPatchPaths(
|
||||
patchPaths
|
||||
)}`,
|
||||
solution:
|
||||
'Open the "__lib__" directory in your workspace and ensure that listed directory names are valid. Only lowercase latin alphabet, numbers, and hypens are allowed.',
|
||||
}),
|
||||
};
|
||||
Reference in New Issue
Block a user