From 8fac5c0e3288b4f6f57438b864c220f8aea03086 Mon Sep 17 00:00:00 2001
From: Pablo Carranza Velez <pablo@resin.io>
Date: Fri, 5 Jan 2018 10:58:17 -0300
Subject: [PATCH 1/2] Avoid problems with null app names or invalid container
 names when migrating from old supervisors

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
---
 src/application.coffee | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/application.coffee b/src/application.coffee
index ccb7fe14..6d61279e 100644
--- a/src/application.coffee
+++ b/src/application.coffee
@@ -288,7 +288,7 @@ isExecFormatError = (err) ->
 generateContainerName = (app) ->
 	randomHexString.generate()
 	.then (randomString) ->
-		sanitisedAppName = app.name.replace(/[^a-zA-Z0-9]+/g, '_')
+		sanitisedAppName = (app.name ? 'app').replace(/[^a-zA-Z0-9]+/g, '_')
 		return "#{sanitisedAppName}_#{randomString}"
 
 application.start = start = (app) ->
@@ -944,7 +944,10 @@ migrateContainerIdApps = ->
 				docker.getContainer(app.containerId).inspect()
 				.catchReturn({ Name: null })
 				.then (container) ->
-					app.containerName = sanitiseContainerName(container.Name)
+					if container.Name?
+						app.containerName = sanitiseContainerName(container.Name)
+					else
+						app.containerName = null
 					app.containerId = null
 					knex('app').update(app).where({ id: app.id })
 		.then ->

From 2fb86421ab9da45ad1de9cd04e5aeae505e118ed Mon Sep 17 00:00:00 2001
From: "resin-io-versionbot[bot]"
 <resin-io-versionbot[bot]@users.noreply.github.com>
Date: Fri, 5 Jan 2018 15:39:11 +0000
Subject: [PATCH 2/2] v6.5.7

---
 CHANGELOG.md | 4 ++++
 package.json | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1191de33..4f9dd224 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
 automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
 This project adheres to [Semantic Versioning](http://semver.org/).
 
+## v6.5.7 - 2018-01-05
+
+* Avoid problems with null app names or invalid container names when migrating from old supervisors #541 [Pablo Carranza Velez]
+
 ## v6.5.6 - 2017-12-15
 
 * Update-locking: updating the documentation with extra  information and tools #528 [Gergely Imreh]
diff --git a/package.json b/package.json
index 648b1bf6..52b4ae1e 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "resin-supervisor",
   "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
-  "version": "6.5.6",
+  "version": "6.5.7",
   "license": "Apache-2.0",
   "repository": {
     "type": "git",