mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-02-02 02:58:13 -05:00
Show warnings instead of panic if some profile is missing.
This commit is contained in:
parent
bae39a247c
commit
623982607c
@ -649,6 +649,15 @@
|
|||||||
"options_formInvalid": {
|
"options_formInvalid": {
|
||||||
"message": "Please correct the errors in this page."
|
"message": "Please correct the errors in this page."
|
||||||
},
|
},
|
||||||
|
"options_profileNotFound": {
|
||||||
|
"message": "Profile $PROFILE$ does not exist! The options may be corrupted.",
|
||||||
|
"placeholders": {
|
||||||
|
"profile": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "Example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"options_resetSuccess": {
|
"options_resetSuccess": {
|
||||||
"message": "Options reset."
|
"message": "Options reset."
|
||||||
},
|
},
|
||||||
|
@ -649,6 +649,15 @@
|
|||||||
"options_formInvalid": {
|
"options_formInvalid": {
|
||||||
"message": "请更正这个页面中的错误。"
|
"message": "请更正这个页面中的错误。"
|
||||||
},
|
},
|
||||||
|
"options_profileNotFound": {
|
||||||
|
"message": "情景模式 $PROFILE$ 不存在!选项可能已经损坏。",
|
||||||
|
"placeholders": {
|
||||||
|
"profile": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "Example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"options_resetSuccess": {
|
"options_resetSuccess": {
|
||||||
"message": "选项已经重置。"
|
"message": "选项已经重置。"
|
||||||
},
|
},
|
||||||
|
@ -649,6 +649,15 @@
|
|||||||
"options_formInvalid": {
|
"options_formInvalid": {
|
||||||
"message": "請更正這個頁面中的錯誤。"
|
"message": "請更正這個頁面中的錯誤。"
|
||||||
},
|
},
|
||||||
|
"options_profileNotFound": {
|
||||||
|
"message": "情景模式 $PROFILE$ 不存在!選項可能已經損壞。",
|
||||||
|
"placeholders": {
|
||||||
|
"profile": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "Example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"options_resetSuccess": {
|
"options_resetSuccess": {
|
||||||
"message": "選項已經重置。"
|
"message": "選項已經重置。"
|
||||||
},
|
},
|
||||||
|
@ -649,6 +649,15 @@
|
|||||||
"options_formInvalid": {
|
"options_formInvalid": {
|
||||||
"message": "請更正這個頁面中的錯誤。"
|
"message": "請更正這個頁面中的錯誤。"
|
||||||
},
|
},
|
||||||
|
"options_profileNotFound": {
|
||||||
|
"message": "情景模式 $PROFILE$ 不存在!選項可能已經損壞。",
|
||||||
|
"placeholders": {
|
||||||
|
"profile": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "Example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"options_resetSuccess": {
|
"options_resetSuccess": {
|
||||||
"message": "選項已經重置。"
|
"message": "選項已經重置。"
|
||||||
},
|
},
|
||||||
|
@ -22,16 +22,21 @@ module.exports =
|
|||||||
compressed_ast.mangle_names()
|
compressed_ast.mangle_names()
|
||||||
compressed_ast
|
compressed_ast
|
||||||
|
|
||||||
script: (options, profile) ->
|
script: (options, profile, args) ->
|
||||||
if typeof profile == 'string'
|
if typeof profile == 'string'
|
||||||
profile = Profiles.byName(profile, options)
|
profile = Profiles.byName(profile, options)
|
||||||
refs = Profiles.allReferenceSet(profile, options)
|
refs = Profiles.allReferenceSet(profile, options,
|
||||||
|
profileNotFound: args?.profileNotFound)
|
||||||
|
|
||||||
profiles = new U2.AST_Object properties:
|
profiles = new U2.AST_Object properties:
|
||||||
for key, name of refs when key != '+direct'
|
for key, name of refs when key != '+direct'
|
||||||
new U2.AST_ObjectKeyVal(
|
p = if typeof profile == 'object' and profile.name == name
|
||||||
key: key
|
profile
|
||||||
value: Profiles.compile(Profiles.byName(name, options) ? profile),
|
else
|
||||||
)
|
Profiles.byName(name, options)
|
||||||
|
if not p?
|
||||||
|
p = Profiles.profileNotFound(name, args?.profileNotFound)
|
||||||
|
new U2.AST_ObjectKeyVal(key: key, value: Profiles.compile(p))
|
||||||
|
|
||||||
factory = new U2.AST_Function(
|
factory = new U2.AST_Function(
|
||||||
argnames: [
|
argnames: [
|
||||||
|
@ -138,22 +138,48 @@ module.exports = exports =
|
|||||||
return cache.directReferenceSet if cache.directReferenceSet
|
return cache.directReferenceSet if cache.directReferenceSet
|
||||||
handler = exports._handler(profile)
|
handler = exports._handler(profile)
|
||||||
cache.directReferenceSet = handler.directReferenceSet.call(exports, profile)
|
cache.directReferenceSet = handler.directReferenceSet.call(exports, profile)
|
||||||
allReferenceSet: (profile, options, opt_out) ->
|
|
||||||
|
profileNotFound: (name, action) ->
|
||||||
|
if not action?
|
||||||
|
throw new Error("Profile #{name} does not exist!")
|
||||||
|
if typeof action == 'function'
|
||||||
|
action = action(name)
|
||||||
|
if typeof action == 'object' and action.profileType
|
||||||
|
return action
|
||||||
|
switch action
|
||||||
|
when 'ignore'
|
||||||
|
return null
|
||||||
|
when 'dumb'
|
||||||
|
return exports.create({
|
||||||
|
name: name
|
||||||
|
profileType: 'VirtualProfile'
|
||||||
|
defaultProfileName: 'direct'
|
||||||
|
})
|
||||||
|
throw action
|
||||||
|
|
||||||
|
allReferenceSet: (profile, options, opt_args) ->
|
||||||
o_profile = profile
|
o_profile = profile
|
||||||
profile = exports.byName(profile, options)
|
profile = exports.byName(profile, options)
|
||||||
throw new Error("Profile #{o_profile} does not exist!") if not profile?
|
profile ?= exports.profileNotFound?(o_profile, opt_args.profileNotFound)
|
||||||
result = opt_out ? {}
|
opt_args ?= {}
|
||||||
result[exports.nameAsKey(profile.name)] = profile.name
|
has_out = opt_args.out?
|
||||||
for key, name of exports.directReferenceSet(profile)
|
result = opt_args.out ?= {}
|
||||||
exports.allReferenceSet(name, options, result)
|
if profile
|
||||||
|
result[exports.nameAsKey(profile.name)] = profile.name
|
||||||
|
for key, name of exports.directReferenceSet(profile)
|
||||||
|
exports.allReferenceSet(name, options, opt_args)
|
||||||
|
delete opt_args.out if not has_out
|
||||||
result
|
result
|
||||||
referencedBySet: (profile, options, opt_out) ->
|
referencedBySet: (profile, options, opt_args) ->
|
||||||
profileKey = exports.nameAsKey(profile)
|
profileKey = exports.nameAsKey(profile)
|
||||||
result = opt_out ? {}
|
opt_args ?= {}
|
||||||
|
has_out = opt_args.out?
|
||||||
|
result = opt_args.out ?= {}
|
||||||
exports.each options, (key, prof) ->
|
exports.each options, (key, prof) ->
|
||||||
if exports.directReferenceSet(prof)[profileKey]
|
if exports.directReferenceSet(prof)[profileKey]
|
||||||
result[key] = prof.name
|
result[key] = prof.name
|
||||||
exports.referencedBySet(prof, options, result)
|
exports.referencedBySet(prof, options, opt_args)
|
||||||
|
delete opt_args.out if not has_out
|
||||||
result
|
result
|
||||||
validResultProfilesFor: (profile, options) ->
|
validResultProfilesFor: (profile, options) ->
|
||||||
profile = exports.byName(profile, options)
|
profile = exports.byName(profile, options)
|
||||||
|
@ -55,6 +55,18 @@ describe 'Profiles', ->
|
|||||||
profile = {}
|
profile = {}
|
||||||
profile = Profiles.byName('profile', {"+profile": profile})
|
profile = Profiles.byName('profile', {"+profile": profile})
|
||||||
profile.should.equal(profile)
|
profile.should.equal(profile)
|
||||||
|
describe '#allReferenceSet', ->
|
||||||
|
profile = Profiles.create('test', 'VirtualProfile')
|
||||||
|
profile.defaultProfileName = 'bogus'
|
||||||
|
it 'should throw if referenced profile does not exist', ->
|
||||||
|
getAllReferenceSet = ->
|
||||||
|
Profiles.allReferenceSet(profile, {})
|
||||||
|
getAllReferenceSet.should.throw(Error)
|
||||||
|
it 'should process a dumb profile for each missing profile if requested', ->
|
||||||
|
profile.defaultProfileName = 'bogus'
|
||||||
|
refs = Profiles.allReferenceSet profile, {}, profileNotFound: 'dumb'
|
||||||
|
refs['+bogus'].should.equal('bogus')
|
||||||
|
|
||||||
describe 'SystemProfile', ->
|
describe 'SystemProfile', ->
|
||||||
it 'should be builtin with the name "system"', ->
|
it 'should be builtin with the name "system"', ->
|
||||||
profile = Profiles.byName('system')
|
profile = Profiles.byName('system')
|
||||||
|
@ -293,6 +293,14 @@ class Options
|
|||||||
###
|
###
|
||||||
watch: (callback) -> @_storage.watch null, callback
|
watch: (callback) -> @_storage.watch null, callback
|
||||||
|
|
||||||
|
_profileNotFound: (name) ->
|
||||||
|
@log.error("Profile #{name} not found! Things may go very, very wrong.")
|
||||||
|
return OmegaPac.Profiles.create({
|
||||||
|
name: name
|
||||||
|
profileType: 'VirtualProfile'
|
||||||
|
defaultProfileName: 'direct'
|
||||||
|
})
|
||||||
|
|
||||||
###*
|
###*
|
||||||
# Get PAC script for profile.
|
# Get PAC script for profile.
|
||||||
# @param {?string|Object} profile The name of the profile, or the profile.
|
# @param {?string|Object} profile The name of the profile, or the profile.
|
||||||
@ -300,7 +308,8 @@ class Options
|
|||||||
# @returns {string} The compiled
|
# @returns {string} The compiled
|
||||||
###
|
###
|
||||||
pacForProfile: (profile, compress = false) ->
|
pacForProfile: (profile, compress = false) ->
|
||||||
ast = OmegaPac.PacGenerator.script(@_options, profile)
|
ast = OmegaPac.PacGenerator.script(@_options, profile,
|
||||||
|
profileNotFound: @_profileNotFound.bind(this))
|
||||||
if compress
|
if compress
|
||||||
ast = OmegaPac.PacGenerator.compress(ast)
|
ast = OmegaPac.PacGenerator.compress(ast)
|
||||||
Promise.resolve OmegaPac.PacGenerator.ascii(ast.print_to_string())
|
Promise.resolve OmegaPac.PacGenerator.ascii(ast.print_to_string())
|
||||||
@ -324,7 +333,8 @@ class Options
|
|||||||
if not allReferenceSet?
|
if not allReferenceSet?
|
||||||
allReferenceSet =
|
allReferenceSet =
|
||||||
if profile
|
if profile
|
||||||
OmegaPac.Profiles.allReferenceSet profile, @_options
|
OmegaPac.Profiles.allReferenceSet(profile, @_options,
|
||||||
|
profileNotFound: @_profileNotFound.bind(this))
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
if allReferenceSet[key]
|
if allReferenceSet[key]
|
||||||
@ -358,7 +368,8 @@ class Options
|
|||||||
|
|
||||||
@_currentProfileName = profile.name
|
@_currentProfileName = profile.name
|
||||||
@_isSystem = options?.system || (profile.profileType == 'SystemProfile')
|
@_isSystem = options?.system || (profile.profileType == 'SystemProfile')
|
||||||
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(profile, @_options)
|
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(profile, @_options,
|
||||||
|
profileNotFound: @_profileNotFound.bind(this))
|
||||||
|
|
||||||
@_state.set({
|
@_state.set({
|
||||||
'currentProfileName': @_currentProfileName
|
'currentProfileName': @_currentProfileName
|
||||||
@ -390,7 +401,7 @@ class Options
|
|||||||
OmegaPac.Profiles.updateRevision(@_tempProfile)
|
OmegaPac.Profiles.updateRevision(@_tempProfile)
|
||||||
|
|
||||||
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(@_tempProfile,
|
@_watchingProfiles = OmegaPac.Profiles.allReferenceSet(@_tempProfile,
|
||||||
@_options)
|
@_options, profileNotFound: @_profileNotFound.bind(this))
|
||||||
@applyProfileProxy(@_tempProfile, profile)
|
@applyProfileProxy(@_tempProfile, profile)
|
||||||
else
|
else
|
||||||
@applyProfileProxy(profile)
|
@applyProfileProxy(profile)
|
||||||
|
@ -27,12 +27,23 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
|
|||||||
return unless profileName
|
return unless profileName
|
||||||
profile = $rootScope.profileByName(profileName)
|
profile = $rootScope.profileByName(profileName)
|
||||||
return if profile.profileType in ['DirectProfile', 'SystemProfile']
|
return if profile.profileType in ['DirectProfile', 'SystemProfile']
|
||||||
ast = OmegaPac.PacGenerator.script($rootScope.options, profileName)
|
missingProfile = null
|
||||||
|
profileNotFound = (name) ->
|
||||||
|
missingProfile = name
|
||||||
|
return 'dumb'
|
||||||
|
ast = OmegaPac.PacGenerator.script($rootScope.options, profileName,
|
||||||
|
profileNotFound: profileNotFound)
|
||||||
pac = ast.print_to_string(beautify: true, comments: true)
|
pac = ast.print_to_string(beautify: true, comments: true)
|
||||||
pac = OmegaPac.PacGenerator.ascii(pac)
|
pac = OmegaPac.PacGenerator.ascii(pac)
|
||||||
blob = new Blob [pac], {type: "text/plain;charset=utf-8"}
|
blob = new Blob [pac], {type: "text/plain;charset=utf-8"}
|
||||||
fileName = profileName.replace(/\W+/g, '_')
|
fileName = profileName.replace(/\W+/g, '_')
|
||||||
saveAs(blob, "OmegaProfile_#{fileName}.pac")
|
saveAs(blob, "OmegaProfile_#{fileName}.pac")
|
||||||
|
if missingProfile
|
||||||
|
$timeout ->
|
||||||
|
$rootScope.showAlert(
|
||||||
|
type: 'error'
|
||||||
|
message: tr('options_profileNotFound', [missingProfile])
|
||||||
|
)
|
||||||
|
|
||||||
diff = jsondiffpatch.create(
|
diff = jsondiffpatch.create(
|
||||||
objectHash: (obj) -> JSON.stringify(obj)
|
objectHash: (obj) -> JSON.stringify(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user