diff --git a/prototype/channel-native/src/hosted_room.rs b/prototype/channel-native/src/hosted_room.rs index 4a80994ee..959dcb74a 100644 --- a/prototype/channel-native/src/hosted_room.rs +++ b/prototype/channel-native/src/hosted_room.rs @@ -46,7 +46,7 @@ impl HostedRoom { pub fn from_backup(path: &Path, backup: &RoomBackup, identity: (Uuid, Uuid)) -> Result { backup_identity(backup, identity)?; - let file_owner = lock(path, &backup.metadata().policy.id)?; + let file_owner = lock(path)?; Self::install(path, file_owner, |staged| { StoredRoomHost::from_backup(staged, backup) }) @@ -64,7 +64,7 @@ impl HostedRoom { } pub fn open(path: &Path, room_id: &str, creator: Uuid) -> Result { - let file_owner = lock(path, room_id)?; + let file_owner = lock(path)?; let host = StoredRoomHost::open(path).map_err(storage_error)?; if host.policy().id != room_id || host.policy().creator_id != creator { bail!("room storage does not belong to this room and admitted identity"); @@ -78,7 +78,7 @@ impl HostedRoom { } pub fn create(path: &Path, policy: RoomState) -> Result { - let file_owner = lock(path, &policy.id)?; + let file_owner = lock(path)?; Self::install(path, file_owner, |staged| { StoredRoomHost::create(staged, policy) }) @@ -234,17 +234,17 @@ pub fn try_lock_file(file: &File) -> io::Result<()> { } #[derive(Debug)] -pub(crate) struct RoomStorageInUse(String); +pub(crate) struct RoomStorageInUse; impl std::fmt::Display for RoomStorageInUse { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "room_storage_in_use: {}", self.0) + f.write_str("room_storage_in_use") } } impl std::error::Error for RoomStorageInUse {} -fn lock(path: &Path, room_id: &str) -> Result { +fn lock(path: &Path) -> Result { let file = std::fs::OpenOptions::new() .create(true) .truncate(false) @@ -253,9 +253,7 @@ fn lock(path: &Path, room_id: &str) -> Result { .open(path.with_added_extension("lock"))?; match try_lock_file(&file) { Ok(()) => Ok(file), - Err(error) if error.kind() == io::ErrorKind::WouldBlock => { - Err(RoomStorageInUse(room_id.into()).into()) - } + Err(error) if error.kind() == io::ErrorKind::WouldBlock => Err(RoomStorageInUse.into()), Err(error) => Err(error.into()), } } @@ -283,7 +281,7 @@ mod tests { let path = folder.path().join("living.sqlite"); let sibling = folder.path().join("quiet.sqlite"); let quiet = HostedRoom::create(&sibling, policy("quiet"))?; - let result = HostedRoom::install(&path, lock(&path, "living")?, |staged| { + let result = HostedRoom::install(&path, lock(&path)?, |staged| { File::create_new(staged)?; assert!(!path.try_exists()?); Err("interrupted_before_schema".into()) @@ -585,13 +583,10 @@ mod tests { let directory = std::env::temp_dir().join(format!("piik-room-lock-{}", Uuid::new_v4())); std::fs::create_dir(&directory)?; let path = directory.join("room.sqlite"); - let owner = lock(&path, "test-room")?; - assert_eq!( - lock(&path, "test-room").unwrap_err().to_string(), - "room_storage_in_use: test-room" - ); + let owner = lock(&path)?; + assert_eq!(lock(&path).unwrap_err().to_string(), "room_storage_in_use"); drop(owner); - drop(lock(&path, "test-room")?); + drop(lock(&path)?); std::fs::remove_file(directory.join("room.sqlite.lock"))?; std::fs::remove_dir(directory)?; Ok(()) diff --git a/src/client/components/error-presentation.ts b/src/client/components/error-presentation.ts index e540256d8..63585e3c0 100644 --- a/src/client/components/error-presentation.ts +++ b/src/client/components/error-presentation.ts @@ -15,7 +15,7 @@ export function channelErrorPresentation(error: string | null, t: (key: CopyKey, if (!error) return { message: null, connectionHelp: true }; const diagnosis = diagnoseChannelFact({ area: "error", code: error }); if (diagnosis) return display(diagnosis.message); - if (error === "room_busy" || error === "capture_pending") return display("channel.error.busy"); + if (error === "room_busy" || error === "capture_pending" || error === "storage_busy") return display("channel.error.busy"); if (error === "room_creation_restricted") return display("channel.error.roomCreationRestricted"); if (error === "room_limit") return display("channel.error.roomLimit"); if (error === "file_transfer_interrupted") return display("channel.attachment.transferInterrupted"); @@ -128,12 +128,12 @@ export function channelErrorPresentation(error: string | null, t: (key: CopyKey, return display("channel.error.videoCodecUnsupported"); if (error === "owner_mismatch") return display("channel.error.ownerMismatch"); - if (/room_host_conflict|room_storage_in_use/.test(error)) + if (error === "room_host_conflict" || error === "room_storage_in_use") return display("channel.error.roomHostConflict"); if (/^(?:room_unavailable|room_not_found|invalid_room_id)$/.test(error)) return display("channel.error.roomUnavailable"); - if (/password/i.test(error)) - return display("channel.error.passwordIncorrect"); + if (error === "invalid_room_password") return display("channel.error.invalidRoomPassword"); + if (error === "password_failed") return display("channel.error.setRoomPasswordFailed"); if (/room_access|room_forbidden/i.test(error)) return display("channel.error.roomAccessDenied"); if (/invit(?:e|ation)/i.test(error)) diff --git a/src/client/locales/en.ts b/src/client/locales/en.ts index 162ecec7a..2ac382f25 100644 --- a/src/client/locales/en.ts +++ b/src/client/locales/en.ts @@ -629,7 +629,8 @@ export const en: Record = { "channel.error.roomHostConflict": "This room is already open elsewhere. Return to the page or App hosting it.", "channel.error.roomHostOffline": "This room is unavailable. Wait for hosting to resume.", "channel.error.roomUnavailable": "The room does not exist or is no longer available.", - "channel.error.passwordIncorrect": "The room password is incorrect. Please try again.", + "channel.error.invalidRoomPassword": "Choose a valid password for this private room.", + "channel.error.setRoomPasswordFailed": "The room password could not be set. Try again.", "channel.error.roomAccessDenied": "You don't have access to this room.", "channel.error.invitationRequired": "A valid invitation is required. Ask the sender for a new, complete link.", "channel.error.invalidOwnerKey": "Invalid operator link. Reopen the site from the App, or check the server’s configured operator key.", diff --git a/src/client/locales/ja.ts b/src/client/locales/ja.ts index f5cc163da..9e53faab2 100644 --- a/src/client/locales/ja.ts +++ b/src/client/locales/ja.ts @@ -520,7 +520,8 @@ export const ja = { "channel.error.roomHostConflict": "このルームはすでに別の場所で開かれています。ホストしているページまたは App に戻ってください。", "channel.error.roomHostOffline": "このルームは利用できません。ホストの再開をお待ちください。", "channel.error.roomUnavailable": "ルームが存在しないか、利用できなくなりました。", - "channel.error.passwordIncorrect": "ルームのパスワードが違います。再試行してください。", + "channel.error.invalidRoomPassword": "この非公開ルームに有効なパスワードを設定してください。", + "channel.error.setRoomPasswordFailed": "ルームのパスワードを設定できませんでした。もう一度お試しください。", "channel.error.roomAccessDenied": "このルームへのアクセス権がありません。", "channel.error.invitationRequired": "有効な招待が必要です。送信者に新しい完全なリンクを依頼してください。", "channel.error.invalidOwnerKey": "運営者リンクが無効です。App からサイトを開き直すか、サーバーの運営者キー設定を確認してください。", diff --git a/src/client/locales/ko.ts b/src/client/locales/ko.ts index 98bedc71a..d6a254a26 100644 --- a/src/client/locales/ko.ts +++ b/src/client/locales/ko.ts @@ -521,7 +521,8 @@ export const ko = { "channel.error.roomHostConflict": "이 방은 다른 곳에서 이미 열려 있어요. 호스팅 중인 페이지나 App으로 돌아가세요.", "channel.error.roomHostOffline": "방을 사용할 수 없어요. 호스팅이 재개될 때까지 기다려 주세요.", "channel.error.roomUnavailable": "방이 존재하지 않거나 더 이상 사용할 수 없어요.", - "channel.error.passwordIncorrect": "방 비밀번호가 올바르지 않아요. 다시 시도해 주세요.", + "channel.error.invalidRoomPassword": "이 비공개 방에 유효한 비밀번호를 설정해 주세요.", + "channel.error.setRoomPasswordFailed": "방 비밀번호를 설정할 수 없어요. 다시 시도해 주세요.", "channel.error.roomAccessDenied": "이 방에 입장할 권한이 없어요.", "channel.error.invitationRequired": "유효한 초대 링크가 필요해요. 보낸 사람에게 새로운 전체 링크를 요청하세요.", "channel.error.invalidOwnerKey": "유효하지 않은 운영자 링크예요. App에서 사이트를 다시 열거나 서버에 설정된 운영자 키를 확인하세요.", diff --git a/src/client/locales/zh-Hant.ts b/src/client/locales/zh-Hant.ts index b25641e44..23e8876d1 100644 --- a/src/client/locales/zh-Hant.ts +++ b/src/client/locales/zh-Hant.ts @@ -520,7 +520,8 @@ export const zhHant = { "channel.error.roomHostConflict": "這間房間已在另一處開啟。請回到正在托管它的頁面或 App。", "channel.error.roomHostOffline": "房間暫不可用,請等待恢復托管。", "channel.error.roomUnavailable": "房間不存在或已不可用。", - "channel.error.passwordIncorrect": "房間密碼不正確,請重新輸入。", + "channel.error.invalidRoomPassword": "請為這個私人房間設定有效的密碼。", + "channel.error.setRoomPasswordFailed": "無法設定房間密碼,請再試一次。", "channel.error.roomAccessDenied": "你還沒有這間房間的存取權限。", "channel.error.invitationRequired": "需要有效邀請。請向邀請方索取新的完整連結。", "channel.error.invalidOwnerKey": "管理連結無效。請重新開啟 App 的站點入口,或核對伺服器組態的管理金鑰。", diff --git a/src/client/locales/zh.ts b/src/client/locales/zh.ts index 607ed42ed..b64371ce7 100644 --- a/src/client/locales/zh.ts +++ b/src/client/locales/zh.ts @@ -627,7 +627,8 @@ export const zh = { "channel.error.roomHostConflict": "这间房间已在另一处打开。请回到正在托管它的页面或 App。", "channel.error.roomHostOffline": "房间暂不可用,请等待恢复托管。", "channel.error.roomUnavailable": "房间不存在或已不可用。", - "channel.error.passwordIncorrect": "房间密码不正确,请重新输入。", + "channel.error.invalidRoomPassword": "请为这个私密房间设置有效密码。", + "channel.error.setRoomPasswordFailed": "未能设置房间密码,请重试。", "channel.error.roomAccessDenied": "你还没有这间房间的访问权限。", "channel.error.invitationRequired": "需要有效邀请。请向邀请方索取新的完整链接。", "channel.error.invalidOwnerKey": "管理链接无效。请重新打开 App 的站点入口,或核对服务端配置的管理密钥。", diff --git a/tests/channel-diagnosis.test.ts b/tests/channel-diagnosis.test.ts index 0c34c12b2..5a547b77e 100644 --- a/tests/channel-diagnosis.test.ts +++ b/tests/channel-diagnosis.test.ts @@ -4,6 +4,15 @@ import { channelErrorPresentation } from "../src/client/components/error-present import { roomOpenFailure } from "../src/client/channel/types"; describe("diagnosis using the current operation", () => { + it("distinguishes setting a password, requesting admission, and contention during a backup", () => { + const message = (code: string) => channelErrorPresentation(code, key => key).message; + expect(message("invalid_room_password")).toBe("channel.error.invalidRoomPassword"); + expect(message("password_failed")).toBe("channel.error.setRoomPasswordFailed"); + expect(message("room_access_required")).toBe("channel.error.roomAccessDenied"); + expect(message("storage_busy")).toBe("channel.error.busy"); + expect(message("room_storage_in_use")).toBe("channel.error.roomHostConflict"); + }); + it("explains when an operation requires peer transport", () => { expect(channelErrorPresentation("peer_transport_unavailable", key => key)).toEqual({ message: "channel.error.peerTransportUnavailable", connectionHelp: false,