|
1 | 1 | use crate::entities::FieldType; |
2 | 2 | use crate::services::cell::{AnyCellData, CellBytes}; |
3 | 3 | use crate::services::field::*; |
| 4 | +use std::fmt::Debug; |
4 | 5 |
|
5 | 6 | use flowy_error::{ErrorCode, FlowyError, FlowyResult}; |
6 | 7 | use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision}; |
@@ -73,20 +74,30 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>( |
73 | 74 | Ok(AnyCellData::new(s, field_type).json()) |
74 | 75 | } |
75 | 76 |
|
76 | | -pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> CellBytes { |
77 | | - if let Ok(any_cell_data) = data.try_into() { |
78 | | - let AnyCellData { data, field_type } = any_cell_data; |
79 | | - let to_field_type = field_rev.ty.into(); |
80 | | - match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) { |
81 | | - Ok(cell_bytes) => cell_bytes, |
82 | | - Err(e) => { |
83 | | - tracing::error!("Decode cell data failed, {:?}", e); |
84 | | - CellBytes::default() |
| 77 | +pub fn decode_any_cell_data<T: TryInto<AnyCellData, Error = FlowyError> + Debug>( |
| 78 | + data: T, |
| 79 | + field_rev: &FieldRevision, |
| 80 | +) -> CellBytes { |
| 81 | + match data.try_into() { |
| 82 | + Ok(any_cell_data) => { |
| 83 | + let AnyCellData { data, field_type } = any_cell_data; |
| 84 | + let to_field_type = field_rev.ty.into(); |
| 85 | + match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) { |
| 86 | + Ok(cell_bytes) => cell_bytes, |
| 87 | + Err(e) => { |
| 88 | + tracing::error!("Decode cell data failed, {:?}", e); |
| 89 | + CellBytes::default() |
| 90 | + } |
85 | 91 | } |
86 | 92 | } |
87 | | - } else { |
88 | | - tracing::error!("Decode type option data failed"); |
89 | | - CellBytes::default() |
| 93 | + Err(err) => { |
| 94 | + tracing::error!( |
| 95 | + "Decode type option data to type: {} failed: {:?}", |
| 96 | + std::any::type_name::<T>(), |
| 97 | + err, |
| 98 | + ); |
| 99 | + CellBytes::default() |
| 100 | + } |
90 | 101 | } |
91 | 102 | } |
92 | 103 |
|
|
0 commit comments