Update more code to new formatting machinery

This commit is contained in:
Lucien Greathouse
2019-11-18 15:18:06 -08:00
parent af866f0665
commit 0c7a94c062
5 changed files with 22 additions and 18 deletions

View File

@@ -133,7 +133,7 @@ function App:startSession(address, port)
-- Details being present indicates that this -- Details being present indicates that this
-- disconnection was from an error. -- disconnection was from an error.
if details ~= nil then if details ~= nil then
Log.warn(tostring(details)) Log.warn("Disconnected from an error: {}", details)
self:setState({ self:setState({
appStatus = AppStatus.Error, appStatus = AppStatus.Error,
@@ -207,7 +207,7 @@ function App:render()
end end
function App:didMount() function App:didMount()
Log.trace("Rojo %s initializing", self.displayedVersion) Log.trace("Rojo {} initializing", self.displayedVersion)
checkUpgrade(self.props.plugin) checkUpgrade(self.props.plugin)
preloadAssets() preloadAssets()

View File

@@ -20,14 +20,16 @@ function InstanceMap.new(onInstanceChanged)
return setmetatable(self, InstanceMap) return setmetatable(self, InstanceMap)
end end
function InstanceMap:debugState() function InstanceMap:__fmtDebug(output)
local buffer = {} output:writeLine("InstanceMap {{")
output:indent()
for id, instance in pairs(self.fromIds) do for id, instance in pairs(self.fromIds) do
table.insert(buffer, string.format("- %s: %s", id, instance:GetFullName())) output:writeLine("- {}: {}", id, instance:GetFullName())
end end
return table.concat(buffer, "\n") output:unindent()
output:writeLine("}")
end end
function InstanceMap:insert(id, instance) function InstanceMap:insert(id, instance)
@@ -44,7 +46,7 @@ function InstanceMap:removeId(id)
self.fromIds[id] = nil self.fromIds[id] = nil
self.fromInstances[instance] = nil self.fromInstances[instance] = nil
else else
Log.warn("Attempted to remove nonexistant ID %s", tostring(id)) Log.warn("Attempted to remove nonexistant ID {}", id)
end end
end end
@@ -56,7 +58,7 @@ function InstanceMap:removeInstance(instance)
self.fromInstances[instance] = nil self.fromInstances[instance] = nil
self.fromIds[id] = nil self.fromIds[id] = nil
else else
Log.warn("Attempted to remove nonexistant instance %s", tostring(instance)) Log.warn("Attempted to remove nonexistant instance {}", instance)
end end
end end
@@ -66,7 +68,7 @@ function InstanceMap:destroyInstance(instance)
if id ~= nil then if id ~= nil then
self:destroyId(id) self:destroyId(id)
else else
Log.warn("Attempted to destroy untracked instance %s", tostring(instance)) Log.warn("Attempted to destroy untracked instance {}", instance)
end end
end end
@@ -89,7 +91,7 @@ function InstanceMap:destroyId(id)
instance:Destroy() instance:Destroy()
else else
Log.warn("Attempted to destroy nonexistant ID %s", tostring(id)) Log.warn("Attempted to destroy nonexistant ID {}", id)
end end
end end

View File

@@ -134,10 +134,10 @@ function Reconciler:applyPatch(patch)
if parentInstance == nil then if parentInstance == nil then
invariant( invariant(
"Cannot add an instance from a patch that has no parent.\nInstance %s with parent %s.\nInstanceMap state:\n%s", "Cannot add an instance from a patch that has no parent.\nInstance {} with parent {}.\nState: {:#?}",
id, id,
tostring(apiInstance.Parent), apiInstance.Parent,
self.__instanceMap:debugState() self.__instanceMap
) )
end end
@@ -150,9 +150,9 @@ function Reconciler:applyPatch(patch)
if instance == nil then if instance == nil then
invariant( invariant(
"Cannot update an instance that does not exist in the reconciler's state.\nInstance ID %s\nInstanceMap state:\n%s", "Cannot update an instance that does not exist in the reconciler's state.\nInstance {}\nState: {:#?}",
update.id, update.id,
self.__instanceMap:debugState() self.__instanceMap
) )
end end

View File

@@ -1,16 +1,18 @@
local Fmt = require(script.Parent.Parent.Fmt)
local Config = require(script.Parent.Config) local Config = require(script.Parent.Config)
local invariant local invariant
if Config.isDevBuild then if Config.isDevBuild then
function invariant(message, ...) function invariant(message, ...)
message = string.format(message, ...) message = Fmt.fmt(message, ...)
error("Invariant violation: " .. message, 2) error("Invariant violation: " .. message, 2)
end end
else else
function invariant(message, ...) function invariant(message, ...)
message = string.format(message, ...) message = Fmt.fmt(message, ...)
local fullMessage = string.format( local fullMessage = string.format(
"Rojo detected an invariant violation within itself:\n" .. "Rojo detected an invariant violation within itself:\n" ..

View File

@@ -19,7 +19,7 @@ local function preloadAssets()
table.insert(contentUrls, url) table.insert(contentUrls, url)
end end
Log.trace("Preloading assets: %s", table.concat(contentUrls, ", ")) Log.trace("Preloading assets: {:?}", contentUrls)
coroutine.wrap(function() coroutine.wrap(function()
ContentProvider:PreloadAsync(contentUrls) ContentProvider:PreloadAsync(contentUrls)