diff --git a/app/attachments.js b/app/attachments.js index 4382ca6fd..cdbf724e4 100644 --- a/app/attachments.js +++ b/app/attachments.js @@ -11,7 +11,7 @@ const PATH = 'attachments.noindex'; // getPath :: AbsolutePath -> AbsolutePath exports.getPath = (userDataPath) => { if (!isString(userDataPath)) { - throw new TypeError('"userDataPath" must be a string'); + throw new TypeError("'userDataPath' must be a string"); } return path.join(userDataPath, PATH); }; @@ -19,7 +19,7 @@ exports.getPath = (userDataPath) => { // ensureDirectory :: AbsolutePath -> IO Unit exports.ensureDirectory = async (userDataPath) => { if (!isString(userDataPath)) { - throw new TypeError('"userDataPath" must be a string'); + throw new TypeError("'userDataPath' must be a string"); } await fse.ensureDir(exports.getPath(userDataPath)); }; @@ -29,12 +29,12 @@ exports.ensureDirectory = async (userDataPath) => { // IO (Promise ArrayBuffer) exports.createReader = (root) => { if (!isString(root)) { - throw new TypeError('"root" must be a path'); + throw new TypeError("'root' must be a path"); } return async (relativePath) => { if (!isString(relativePath)) { - throw new TypeError('"relativePath" must be a string'); + throw new TypeError("'relativePath' must be a string"); } const absolutePath = path.join(root, relativePath); @@ -48,12 +48,12 @@ exports.createReader = (root) => { // IO (Promise RelativePath) exports.createWriterForNew = (root) => { if (!isString(root)) { - throw new TypeError('"root" must be a path'); + throw new TypeError("'root' must be a path"); } return async (arrayBuffer) => { if (!isArrayBuffer(arrayBuffer)) { - throw new TypeError('"arrayBuffer" must be an array buffer'); + throw new TypeError("'arrayBuffer' must be an array buffer"); } const name = exports.createName(); @@ -70,16 +70,16 @@ exports.createWriterForNew = (root) => { // IO (Promise RelativePath) exports.createWriterForExisting = (root) => { if (!isString(root)) { - throw new TypeError('"root" must be a path'); + throw new TypeError("'root' must be a path"); } return async ({ data: arrayBuffer, path: relativePath } = {}) => { if (!isString(relativePath)) { - throw new TypeError('"relativePath" must be a path'); + throw new TypeError("'relativePath' must be a path"); } if (!isArrayBuffer(arrayBuffer)) { - throw new TypeError('"arrayBuffer" must be an array buffer'); + throw new TypeError("'arrayBuffer' must be an array buffer"); } const buffer = Buffer.from(arrayBuffer); @@ -95,12 +95,12 @@ exports.createWriterForExisting = (root) => { // IO Unit exports.createDeleter = (root) => { if (!isString(root)) { - throw new TypeError('"root" must be a path'); + throw new TypeError("'root' must be a path"); } return async (relativePath) => { if (!isString(relativePath)) { - throw new TypeError('"relativePath" must be a string'); + throw new TypeError("'relativePath' must be a string"); } const absolutePath = path.join(root, relativePath); @@ -117,7 +117,7 @@ exports.createName = () => { // getRelativePath :: String -> IO Path exports.getRelativePath = (name) => { if (!isString(name)) { - throw new TypeError('"name" must be a string'); + throw new TypeError("'name' must be a string"); } const prefix = name.slice(0, 2); diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 05c6dc658..6696b0954 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -100,11 +100,11 @@ }, getOrCreate: function(id, type) { if (typeof id !== 'string') { - throw new TypeError('"id" must be a string'); + throw new TypeError("'id' must be a string"); } if (type !== 'private' && type !== 'group') { - throw new TypeError('"type" must be "private" or "group"; got: ' + type); + throw new TypeError(`'type' must be 'private' or 'group'; got: '${type}'`); } if (!this._initialFetchComplete) { diff --git a/js/modules/backup.js b/js/modules/backup.js index 0f9197735..b8158f6cf 100644 --- a/js/modules/backup.js +++ b/js/modules/backup.js @@ -496,7 +496,7 @@ async function writeAttachment(attachment, options) { } if (!Attachment.hasData(attachment)) { - throw new TypeError('"attachment.data" is required'); + throw new TypeError("'attachment.data' is required"); } const ciphertext = await crypto.encryptSymmetric(key, attachment.data); diff --git a/js/modules/database.js b/js/modules/database.js index 341ed166f..e8527d254 100644 --- a/js/modules/database.js +++ b/js/modules/database.js @@ -56,7 +56,7 @@ exports.getVersion = async (name) => { exports.getCount = async ({ store } = {}) => { if (!isObject(store)) { - throw new TypeError('"store" is required'); + throw new TypeError("'store' is required"); } const request = store.count(); diff --git a/js/modules/debug.js b/js/modules/debug.js index b89ee17fa..5de466bca 100644 --- a/js/modules/debug.js +++ b/js/modules/debug.js @@ -29,15 +29,15 @@ exports.createConversation = async ({ } = {}) => { if (!isObject(ConversationController) || !isFunction(ConversationController.getOrCreateAndWait)) { - throw new TypeError('"ConversationController" is required'); + throw new TypeError("'ConversationController' is required"); } if (!isNumber(numMessages) || numMessages <= 0) { - throw new TypeError('"numMessages" must be a positive number'); + throw new TypeError("'numMessages' must be a positive number"); } if (!isFunction(WhisperMessage)) { - throw new TypeError('"WhisperMessage" is required'); + throw new TypeError("'WhisperMessage' is required"); } const conversation = @@ -80,7 +80,7 @@ const SAMPLE_MESSAGES = [ const ATTACHMENT_SAMPLE_RATE = 0.33; const createRandomMessage = async ({ conversationId } = {}) => { if (!isString(conversationId)) { - throw new TypeError('"conversationId" must be a string'); + throw new TypeError("'conversationId' must be a string"); } const sentAt = Date.now() - random(100 * 24 * 60 * 60 * 1000); diff --git a/js/modules/messages_data_migrator.js b/js/modules/messages_data_migrator.js index c81d71daa..3f70f0f87 100644 --- a/js/modules/messages_data_migrator.js +++ b/js/modules/messages_data_migrator.js @@ -29,20 +29,20 @@ exports.processNext = async ({ upgradeMessageSchema, } = {}) => { if (!isFunction(BackboneMessage)) { - throw new TypeError('"BackboneMessage" (Whisper.Message) constructor is required'); + throw new TypeError("'BackboneMessage' (Whisper.Message) constructor is required"); } if (!isFunction(BackboneMessageCollection)) { - throw new TypeError('"BackboneMessageCollection" (Whisper.MessageCollection)' + + throw new TypeError("'BackboneMessageCollection' (Whisper.MessageCollection)" + ' constructor is required'); } if (!isNumber(numMessagesPerBatch)) { - throw new TypeError('"numMessagesPerBatch" is required'); + throw new TypeError("'numMessagesPerBatch' is required"); } if (!isFunction(upgradeMessageSchema)) { - throw new TypeError('"upgradeMessageSchema" is required'); + throw new TypeError("'upgradeMessageSchema' is required"); } const startTime = Date.now(); @@ -85,19 +85,19 @@ exports.dangerouslyProcessAllWithoutIndex = async ({ upgradeMessageSchema, } = {}) => { if (!isString(databaseName)) { - throw new TypeError('"databaseName" must be a string'); + throw new TypeError("'databaseName' must be a string"); } if (!isNumber(minDatabaseVersion)) { - throw new TypeError('"minDatabaseVersion" must be a number'); + throw new TypeError("'minDatabaseVersion' must be a number"); } if (!isNumber(numMessagesPerBatch)) { - throw new TypeError('"numMessagesPerBatch" must be a number'); + throw new TypeError("'numMessagesPerBatch' must be a number"); } if (!isFunction(upgradeMessageSchema)) { - throw new TypeError('"upgradeMessageSchema" is required'); + throw new TypeError("'upgradeMessageSchema' is required"); } const connection = await database.open(databaseName); @@ -155,7 +155,7 @@ exports.processNextBatchWithoutIndex = async ({ upgradeMessageSchema, } = {}) => { if (!isFunction(upgradeMessageSchema)) { - throw new TypeError('"upgradeMessageSchema" is required'); + throw new TypeError("'upgradeMessageSchema' is required"); } const connection = await _getConnection({ databaseName, minDatabaseVersion }); @@ -170,11 +170,11 @@ exports.processNextBatchWithoutIndex = async ({ // Private API const _getConnection = async ({ databaseName, minDatabaseVersion }) => { if (!isString(databaseName)) { - throw new TypeError('"databaseName" must be a string'); + throw new TypeError("'databaseName' must be a string"); } if (!isNumber(minDatabaseVersion)) { - throw new TypeError('"minDatabaseVersion" must be a number'); + throw new TypeError("'minDatabaseVersion' must be a number"); } const connection = await database.open(databaseName); @@ -194,15 +194,15 @@ const _processBatch = async ({ upgradeMessageSchema, } = {}) => { if (!isObject(connection)) { - throw new TypeError('"connection" must be a string'); + throw new TypeError("'connection' must be a string"); } if (!isFunction(upgradeMessageSchema)) { - throw new TypeError('"upgradeMessageSchema" is required'); + throw new TypeError("'upgradeMessageSchema' is required"); } if (!isNumber(numMessagesPerBatch)) { - throw new TypeError('"numMessagesPerBatch" is required'); + throw new TypeError("'numMessagesPerBatch' is required"); } const isAttachmentMigrationComplete = @@ -273,7 +273,7 @@ const _saveMessageBackbone = ({ BackboneMessage } = {}) => (message) => { const _saveMessage = ({ transaction } = {}) => (message) => { if (!isObject(transaction)) { - throw new TypeError('"transaction" is required'); + throw new TypeError("'transaction' is required"); } const messagesStore = transaction.objectStore(MESSAGES_STORE_NAME); @@ -289,12 +289,12 @@ const _saveMessage = ({ transaction } = {}) => (message) => { const _fetchMessagesRequiringSchemaUpgrade = async ({ BackboneMessageCollection, count } = {}) => { if (!isFunction(BackboneMessageCollection)) { - throw new TypeError('"BackboneMessageCollection" (Whisper.MessageCollection)' + + throw new TypeError("'BackboneMessageCollection' (Whisper.MessageCollection)" + ' constructor is required'); } if (!isNumber(count)) { - throw new TypeError('"count" is required'); + throw new TypeError("'count' is required"); } const collection = new BackboneMessageCollection(); @@ -318,15 +318,15 @@ const _fetchMessagesRequiringSchemaUpgrade = const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex = ({ connection, count, lastIndex } = {}) => { if (!isObject(connection)) { - throw new TypeError('"connection" is required'); + throw new TypeError("'connection' is required"); } if (!isNumber(count)) { - throw new TypeError('"count" is required'); + throw new TypeError("'count' is required"); } if (lastIndex && !isString(lastIndex)) { - throw new TypeError('"lastIndex" must be a string'); + throw new TypeError("'lastIndex' must be a string"); } const hasLastIndex = Boolean(lastIndex); @@ -359,7 +359,7 @@ const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex = const _getNumMessages = async ({ connection } = {}) => { if (!isObject(connection)) { - throw new TypeError('"connection" is required'); + throw new TypeError("'connection' is required"); } const transaction = connection.transaction(MESSAGES_STORE_NAME, 'readonly'); diff --git a/js/modules/migrations/run_migrations.js b/js/modules/migrations/run_migrations.js index cc54a408c..9db4d5020 100644 --- a/js/modules/migrations/run_migrations.js +++ b/js/modules/migrations/run_migrations.js @@ -19,12 +19,12 @@ const closeDatabaseConnection = ({ Backbone } = {}) => exports.runMigrations = async ({ Backbone, database } = {}) => { if (!isObject(Backbone) || !isObject(Backbone.Collection) || !isFunction(Backbone.Collection.extend)) { - throw new TypeError('"Backbone" is required'); + throw new TypeError("'Backbone' is required"); } if (!isObject(database) || !isString(database.id) || !Array.isArray(database.migrations)) { - throw new TypeError('"database" is required'); + throw new TypeError("'database' is required"); } const { @@ -58,7 +58,7 @@ exports.runMigrations = async ({ Backbone, database } = {}) => { const getMigrationVersions = (database) => { if (!isObject(database) || !Array.isArray(database.migrations)) { - throw new TypeError('"database" is required'); + throw new TypeError("'database' is required"); } const firstMigration = head(database.migrations); diff --git a/js/modules/privacy.js b/js/modules/privacy.js index b3cf2cef2..e476a6b22 100644 --- a/js/modules/privacy.js +++ b/js/modules/privacy.js @@ -16,14 +16,14 @@ const REDACTION_PLACEHOLDER = '[REDACTED]'; // _redactPath :: Path -> String -> String exports._redactPath = (filePath) => { if (!is.string(filePath)) { - throw new TypeError('"filePath" must be a string'); + throw new TypeError("'filePath' must be a string"); } const filePathPattern = exports._pathToRegExp(filePath); return (text) => { if (!is.string(text)) { - throw new TypeError('"text" must be a string'); + throw new TypeError("'text' must be a string"); } if (!is.regExp(filePathPattern)) { @@ -58,7 +58,7 @@ exports._pathToRegExp = (filePath) => { // redactPhoneNumbers :: String -> String exports.redactPhoneNumbers = (text) => { if (!is.string(text)) { - throw new TypeError('"text" must be a string'); + throw new TypeError("'text' must be a string"); } return text.replace(PHONE_NUMBER_PATTERN, `+${REDACTION_PLACEHOLDER}$1`); @@ -67,7 +67,7 @@ exports.redactPhoneNumbers = (text) => { // redactGroupIds :: String -> String exports.redactGroupIds = (text) => { if (!is.string(text)) { - throw new TypeError('"text" must be a string'); + throw new TypeError("'text' must be a string"); } return text.replace( diff --git a/js/modules/settings.js b/js/modules/settings.js index a4c609ccd..1d63b1e5b 100644 --- a/js/modules/settings.js +++ b/js/modules/settings.js @@ -26,11 +26,11 @@ exports.markAttachmentMigrationComplete = connection => // Private API exports._getItem = (connection, key) => { if (!isObject(connection)) { - throw new TypeError('"connection" is required'); + throw new TypeError("'connection' is required"); } if (!isString(key)) { - throw new TypeError('"key" must be a string'); + throw new TypeError("'key' must be a string"); } const transaction = connection.transaction(ITEMS_STORE_NAME, 'readonly'); @@ -47,11 +47,11 @@ exports._getItem = (connection, key) => { exports._setItem = (connection, key, value) => { if (!isObject(connection)) { - throw new TypeError('"connection" is required'); + throw new TypeError("'connection' is required"); } if (!isString(key)) { - throw new TypeError('"key" must be a string'); + throw new TypeError("'key' must be a string"); } const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite'); @@ -68,11 +68,11 @@ exports._setItem = (connection, key, value) => { exports._deleteItem = (connection, key) => { if (!isObject(connection)) { - throw new TypeError('"connection" is required'); + throw new TypeError("'connection' is required"); } if (!isString(key)) { - throw new TypeError('"key" must be a string'); + throw new TypeError("'key' must be a string"); } const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite'); diff --git a/js/modules/startup.js b/js/modules/startup.js index fc60861de..06d950623 100644 --- a/js/modules/startup.js +++ b/js/modules/startup.js @@ -10,15 +10,15 @@ exports.syncReadReceiptConfiguration = async ({ storage, }) => { if (!is.string(deviceId)) { - throw new TypeError('"deviceId" is required'); + throw new TypeError("'deviceId' is required"); } if (!is.function(sendRequestConfigurationSyncMessage)) { - throw new TypeError('"sendRequestConfigurationSyncMessage" is required'); + throw new TypeError("'sendRequestConfigurationSyncMessage' is required"); } if (!is.object(storage)) { - throw new TypeError('"storage" is required'); + throw new TypeError("'storage' is required"); } const isPrimaryDevice = deviceId === '1'; diff --git a/js/modules/string_to_array_buffer.js b/js/modules/string_to_array_buffer.js index 4c6fa700c..3ddd19d5b 100644 --- a/js/modules/string_to_array_buffer.js +++ b/js/modules/string_to_array_buffer.js @@ -1,6 +1,6 @@ exports.stringToArrayBuffer = (string) => { if (typeof string !== 'string') { - throw new TypeError('"string" must be a string'); + throw new TypeError("'string' must be a string"); } const array = new Uint8Array(string.length); diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index c807afc2b..06298b284 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -116,12 +116,12 @@ exports.hasData = attachment => // IO (Promise Attachment) exports.loadData = (readAttachmentData) => { if (!isFunction(readAttachmentData)) { - throw new TypeError('"readAttachmentData" must be a function'); + throw new TypeError("'readAttachmentData' must be a function"); } return async (attachment) => { if (!exports.isValid(attachment)) { - throw new TypeError('"attachment" is not valid'); + throw new TypeError("'attachment' is not valid"); } const isAlreadyLoaded = exports.hasData(attachment); @@ -130,7 +130,7 @@ exports.loadData = (readAttachmentData) => { } if (!isString(attachment.path)) { - throw new TypeError('"attachment.path" is required'); + throw new TypeError("'attachment.path' is required"); } const data = await readAttachmentData(attachment.path); @@ -143,12 +143,12 @@ exports.loadData = (readAttachmentData) => { // IO Unit exports.deleteData = (deleteAttachmentData) => { if (!isFunction(deleteAttachmentData)) { - throw new TypeError('"deleteAttachmentData" must be a function'); + throw new TypeError("'deleteAttachmentData' must be a function"); } return async (attachment) => { if (!exports.isValid(attachment)) { - throw new TypeError('"attachment" is not valid'); + throw new TypeError("'attachment' is not valid"); } const hasDataInMemory = exports.hasData(attachment); @@ -157,7 +157,7 @@ exports.deleteData = (deleteAttachmentData) => { } if (!isString(attachment.path)) { - throw new TypeError('"attachment.path" is required'); + throw new TypeError("'attachment.path' is required"); } await deleteAttachmentData(attachment.path); diff --git a/js/modules/types/attachment/migrate_data_to_file_system.js b/js/modules/types/attachment/migrate_data_to_file_system.js index 9fa4fc83d..debf2d2ca 100644 --- a/js/modules/types/attachment/migrate_data_to_file_system.js +++ b/js/modules/types/attachment/migrate_data_to_file_system.js @@ -15,7 +15,7 @@ const { // Promise Attachment exports.migrateDataToFileSystem = async (attachment, { writeNewAttachmentData } = {}) => { if (!isFunction(writeNewAttachmentData)) { - throw new TypeError('"writeNewAttachmentData" must be a function'); + throw new TypeError("'writeNewAttachmentData' must be a function"); } const { data } = attachment; diff --git a/js/modules/types/message.js b/js/modules/types/message.js index f8d5f40c1..f17bcf88b 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -81,10 +81,10 @@ exports.initializeSchemaVersion = (message) => { // SchemaVersion -> UpgradeStep -> UpgradeStep exports._withSchemaVersion = (schemaVersion, upgrade) => { if (!SchemaVersion.isValid(schemaVersion)) { - throw new TypeError('"schemaVersion" is invalid'); + throw new TypeError("'schemaVersion' is invalid"); } if (!isFunction(upgrade)) { - throw new TypeError('"upgrade" must be a function'); + throw new TypeError("'upgrade' must be a function"); } return async (message, context) => { @@ -192,12 +192,12 @@ exports.createAttachmentLoader = (loadAttachmentData) => { // IO (Promise Message) exports.createAttachmentDataWriter = (writeExistingAttachmentData) => { if (!isFunction(writeExistingAttachmentData)) { - throw new TypeError('"writeExistingAttachmentData" must be a function'); + throw new TypeError("'writeExistingAttachmentData' must be a function"); } return async (rawMessage) => { if (!exports.isValid(rawMessage)) { - throw new TypeError('"rawMessage" is not valid'); + throw new TypeError("'rawMessage' is not valid"); } const message = exports.initializeSchemaVersion(rawMessage); @@ -217,11 +217,11 @@ exports.createAttachmentDataWriter = (writeExistingAttachmentData) => { attachments.forEach((attachment) => { if (!Attachment.hasData(attachment)) { - throw new TypeError('"attachment.data" is required during message import'); + throw new TypeError("'attachment.data' is required during message import"); } if (!isString(attachment.path)) { - throw new TypeError('"attachment.path" is required during message import'); + throw new TypeError("'attachment.path' is required during message import"); } }); diff --git a/test/modules/types/message_test.js b/test/modules/types/message_test.js index c9c4b5881..7a8af0223 100644 --- a/test/modules/types/message_test.js +++ b/test/modules/types/message_test.js @@ -246,14 +246,14 @@ describe('Message', () => { const toVersionX = () => {}; assert.throws( () => Message._withSchemaVersion(toVersionX, 2), - '"schemaVersion" is invalid' + "'schemaVersion' is invalid" ); }); it('should require an upgrade function', () => { assert.throws( () => Message._withSchemaVersion(2, 3), - '"upgrade" must be a function' + "'upgrade' must be a function" ); });