feat: improve error handling and storage status reporting in BrainyData
Updated error messages for initialization failures to use "BrainyData" for clarity. Enhanced `getStorageStatus` to handle storage adapters without the `getStorageStatus` method, ensuring proper reporting of storage type, usage, and adapter details.
This commit is contained in:
parent
426f01cea0
commit
e42c6b7302
1 changed files with 33 additions and 6 deletions
|
|
@ -108,8 +108,8 @@ export class BrainyData<T = any> {
|
||||||
|
|
||||||
this.isInitialized = true
|
this.isInitialized = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize vector database:', error)
|
console.error('Failed to initialize BrainyData:', error)
|
||||||
throw new Error(`Failed to initialize vector database: ${error}`)
|
throw new Error(`Failed to initialize BrainyData: ${error}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,6 +628,22 @@ export class BrainyData<T = any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Check if the storage adapter has a getStorageStatus method
|
||||||
|
if (typeof this.storage.getStorageStatus !== 'function') {
|
||||||
|
// If not, determine the storage type based on the constructor name
|
||||||
|
const storageType = this.storage.constructor.name.toLowerCase().replace('storage', '');
|
||||||
|
return {
|
||||||
|
type: storageType || 'unknown',
|
||||||
|
used: 0,
|
||||||
|
quota: null,
|
||||||
|
details: {
|
||||||
|
error: 'Storage adapter does not implement getStorageStatus method',
|
||||||
|
storageAdapter: this.storage.constructor.name,
|
||||||
|
indexSize: this.size()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get storage status from the storage adapter
|
// Get storage status from the storage adapter
|
||||||
const storageStatus = await this.storage.getStorageStatus()
|
const storageStatus = await this.storage.getStorageStatus()
|
||||||
|
|
||||||
|
|
@ -636,20 +652,31 @@ export class BrainyData<T = any> {
|
||||||
indexSize: this.size()
|
indexSize: this.size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure all required fields are present
|
||||||
return {
|
return {
|
||||||
...storageStatus,
|
type: storageStatus.type || 'unknown',
|
||||||
|
used: storageStatus.used || 0,
|
||||||
|
quota: storageStatus.quota || null,
|
||||||
details: {
|
details: {
|
||||||
...storageStatus.details,
|
...(storageStatus.details || {}),
|
||||||
index: indexInfo
|
index: indexInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to get storage status:', error)
|
console.error('Failed to get storage status:', error)
|
||||||
|
|
||||||
|
// Determine the storage type based on the constructor name
|
||||||
|
const storageType = this.storage.constructor.name.toLowerCase().replace('storage', '');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'unknown',
|
type: storageType || 'unknown',
|
||||||
used: 0,
|
used: 0,
|
||||||
quota: null,
|
quota: null,
|
||||||
details: { error: String(error) }
|
details: {
|
||||||
|
error: String(error),
|
||||||
|
storageAdapter: this.storage.constructor.name,
|
||||||
|
indexSize: this.size()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue