Skip to content
Snippets Groups Projects
Commit 77666b38 authored by Iain Bryson's avatar Iain Bryson
Browse files

Make the client logging more robust to circular JSON. Add a helper exec method...

Make the client logging more robust to circular JSON. Add a helper exec method to the git service to enable “raw” use of Git.
parent d3ab2c37
Branches
Tags 1.0
No related merge requests found
......@@ -12,10 +12,14 @@ var ClientDebug = {
message: message
};
var json = stringifySafe(packet, null, 2)
$.ajax({
method: "PUT",
url: ClientDebug.resource_url,
data: JSON.stringify(packet, null, 2)
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: json
})
.done(function(data, textStatus, jqXHR) {
console.log("client log: success")
......
// from https://github.com/isaacs/json-stringify-safe/blob/02cfafd45f06d076ac4bf0dd28be6738a07a72f9/stringify.js#L4
// per http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json
// to avoid circular refs error when logging mathjax errors
function stringifySafe(obj, replacer, spaces, cycleReplacer) {
return JSON.stringify(obj, serializerSafe(replacer, cycleReplacer), spaces)
}
function serializerSafe(replacer, cycleReplacer) {
var stack = [],
keys = []
if (cycleReplacer == null) cycleReplacer = function(key, value) {
if (stack[0] === value) return "[Circular ~]"
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]"
}
return function(key, value) {
if (stack.length > 0) {
var thisPos = stack.indexOf(this);
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
} else stack.push(value)
return replacer == null ? value : replacer.call(this, key, value)
}
}
\ No newline at end of file
......@@ -19,9 +19,10 @@ window.onerror = (msg, url, lineNo, columnNo, error) ->
do ->
kinds = ['log', 'warn', 'error', 'info']
window._CONSOLE = {}
for kind in kinds
oldLog = console[kind]
if typeof oldLog is 'function'
window._CONSOLE[kind] = console[kind]
if typeof window._CONSOLE is 'function'
console[kind] = (message) ->
ConsoleBuffer.log({kind: kind, message: message})
oldLog.apply(console, arguments)
_CONSOLE[kind].apply(console, arguments)
......@@ -153,6 +153,16 @@ module DtuCore
true
end
def exec()
begin
g = Git.open(self.git_repo_info.local_repo_folder, :log => Rails.logger)
set_git_identity(g)
yield g
rescue => e
Rails.logger.warn "Unable to change, will ignore: #{e}"
end
end
def set_git_identity(g)
g.config('user.name', (self.git_user.full_name || 'aonymous') + ' [from DTU quiz]')
g.config('user.email', self.git_user.email)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment